matlab answers -凯发k8网页登录
https://ww2.mathworks.cn/matlabcentral/answers/questions
matlab answers -凯发k8网页登录
2023-06-08t04:58:04z
tag:ww2.mathworks.cn,2005:question/1978434
2023-06-05t10:49:39z
2023-06-08t04:58:04z
use of fminimax function to solve minimax game
when i am using the fminimax function i am getting the same answer when i provide the different values of lambda. i have defined my utility function as different .m file.
�fine the parameters and constants
n = 5; % number of rows
m = 4; % number of columns
% define the matrices r, p, and d (example values)
r0= [1, 1, 1, 1; 1, 1, 1, 1; 1, 1, 1, 1; 1, 1, 1, 1; 1, 1, 1, 1]; % n x m matrix
lambda= [0.02, 0.02, 0.02, 0.02; 0.02, 0.02, 0.02, 0.02;
0.02, 0.02, 0.02, 0.02; 0.02, 0.02, 0.02, 0.02;
0.02, 0.02, 0.02, 0.02]; % n x m matrix
d= [33, 38, 5, 38; 2, 15, 3, 4;
19, 29, 13, 7; 7, 45, 43, 19;
25, 22, 15, 25];
c0=[299, 253, 196, 227, 204]; initial guess
u=utility_3(r0,lambda,c0,d,n,m);
f=@utility_3;
lb = [0,0,0,0,0]; % lower bounds
ub = [300,300,300,300,300]; % upper bounds
aeq=[1,1,1,1,1]; %coefficient vector of ci
beq=[394]; %budget
[c, fval,maxfval,output] = fminimax(f, c0, [], [], aeq, beq, lb, ub);
% print the optimal solution and objective value
disp('allocation:');
disp(c);
disp('expected loss:');
disp(fval);
disp('maximum expected loss and attack strategy');
disp(max(fval,[],2));
akshay tanaji bhosale
https://ww2.mathworks.cn/matlabcentral/profile/authors/17661447
tag:ww2.mathworks.cn,2005:question/1977734
2023-06-03t13:32:56z
2023-06-08t04:57:36z
one of the colorbars is going out of the figure window
i am trying to bring two pcolor plots on top of each other with different colormaps. one of the colorbars goes out of the figure window, have tried placing the colorbar in other places like southoutside or westoutside and the same problem persists. is there any better way to do it? any help is appreciated.
f = figure;
ax = gca;
ax(2) = copyobj(ax, ax.parent);
linkprop([ax(1), ax(2)], {'xlim', 'ylim','position', 'view'});
p = pcolor(ax(1), xc, yc, e);
set(p, 'edgecolor', 'none', 'facealpha', 1);
set(ax(1), 'colormap', bone);
cb(1) = colorbar(ax(1), 'eastoutside');
p2 = pcolor(ax(2), xc, yc, d);
set(p2, 'edgecolor', 'none', 'facealpha', 0.5);
set(ax(2), 'colormap', copper);
cb(2) = colorbar(ax(2), 'northoutside');
ax(2).visible = 'off';
ax(1).xaxis.fontsize = 14;
ax(1).yaxis.fontsize = 14;
ax(2).xaxis.fontsize = 14;
ax(2).yaxis.fontsize = 14;
ax(1).fontsize = 14;
ax(2).fontsize = 14;
xlabel('x(\mum)');
ylabel('y(\mum)');
%exportgraphics(gcf, 'trial.png', 'resolution', 300);
santhosh krishnamurthy
https://ww2.mathworks.cn/matlabcentral/profile/authors/14681694
tag:ww2.mathworks.cn,2005:question/1933210
2023-03-22t08:45:32z
2023-06-08t04:55:07z
assistance on offline installation of documentation
i went through the referred link and i am failing to comprehend step 2 and 3. i am kindly requesting for the meaning of "navigate to bin/, where is the operating system for this computer." because when i try to run the step 3 command on cmd
, i am getting the error "mpm not recognized as an internal or external command"
ivan tadiwanashe chuma
https://ww2.mathworks.cn/matlabcentral/profile/authors/16822839
tag:ww2.mathworks.cn,2005:question/1979164
2023-06-06t14:55:24z
2023-06-08t04:48:37z
euro sign when using latex interpreter
this has been asked before, of course, but not in a couple of years, so i'd like to ask again: is it possibly by now to use the euro symbol, €, when using latex as the interpreter, e.g. for legend entries? and if so, how?
something as simple as
text(.5, .5, "€", "interpreter", "latex")
breaks, as does (\texteuro requires no additional packages anymore these days btw)
text(.5, .5, "\texteuro", "interpreter", "latex")
and this is rather annoying: consider the case where one (and only one!) of your legend entries in a more complicated plot is suddenly rendered using the tex interpreter, say.
people have asked about this in 2015, in 2017 (twice), and in 2018, and the answer's always been "this is not possible".
it's been years since then. matlab is a commercial product with outstanding development and support teams, and does not come cheap. i hope that this time, the answer will be "yes, this has been implemented" (or at the very least, "no, not yet, but we will do so for the next release"; i'll be happy to file an rfe in that case if it helps).
thanks,
chris
christian schröder
https://ww2.mathworks.cn/matlabcentral/profile/authors/15363629
tag:ww2.mathworks.cn,2005:question/1979814
2023-06-07t17:15:51z
2023-06-08t04:39:00z
old simulink models wont run in 2023a, requires aerospace toolbox, did not before
all older versions of our simulink model do not run in 2023a due to wanting aerospace toolbox. we do not have that tool box and we have never had it. we have not changed the simulink model. how can i get my model functional again? i have tried openeing in 2023a and saving to older format and repoening but it still flags the blocks as needing aerospace blockset/toolbox. thank you very much!
valerie
https://ww2.mathworks.cn/matlabcentral/profile/authors/28516695
tag:ww2.mathworks.cn,2005:question/1979929
2023-06-08t00:46:23z
2023-06-08t04:38:53z
imufilter results seem incorrect
hi,
i used an imu to collect acceleration and gyroscope that are under the sensor's local coordinate system. the local acceleration and gyroscope were low-pass filtered with cut-off frequency of 10hz. then i used imufilter to calculate the rotation matrix and transformed the local acceleration. the code is as follows.
% read csv file
data = readmatrix(data_path);
timestamp = data(:, 1);
acc = data(:, 2:4); % acc size: n * 3
gyro = data(:, 5:7);
% calculate orientation
fuse = imufilter('samplerate', 50, 'orientationformat', 'rotation matrix');
[orientation, ] = fuse(acc, gyro); % orientation size: 3 * 3 * n
% transform acc
[rows, cols] = size(acc);
earth_acc = zeros(rows, cols);
for n = 1:rows
earth_acc(i, :) = acc(i, :) * orientation(:, :, i);
end
then the transformed acceleration seems to be incorrect. to be more specific, the local acceleration looks like the following picture, where x-axis is frame, and y-axis is acceleration (m/s^2).
however, the transformed acceleration looks like the following picture. to me, it just looks like noise.
can you please help me to figure out what is going on with the code? thank you!
yunda liu
https://ww2.mathworks.cn/matlabcentral/profile/authors/17129473
tag:ww2.mathworks.cn,2005:question/1979944
2023-06-08t02:37:01z
2023-06-08t04:37:19z
dpigen post-generation command failure
hi,
i'm currently running r2017b matlab. i ran into an issue where it shows "error evaluating the post generation command" dynamic allocated array are not supported in dpi-c component. however, from the report, i didn't see any issue related to the code except for this error message. it seems to be related to the building process. it would be very much appreciated if there is a recommended mechanism to debug this issue such as more information and an insight on what might be a potential issue.
thank you very much,
tsung-chi chang
tsung-chi chang
https://ww2.mathworks.cn/matlabcentral/profile/authors/20619766
tag:ww2.mathworks.cn,2005:question/1979774
2023-06-07t15:16:56z
2023-06-08t04:34:00z
function optimization meeting a condition
how can i optimize the i function, i want to find the values of h(j) that minimize i, meetentig the condition h(j 1)>h(j)?
ht is a array beiing its size ht(lt,lc) or the same ht(i,j) and it is calculated in another function. the formula of ins is ins=ht(i,j)-h(j).
in the problem i want to solve, i have a matrix ht(i,j), which means there is a value ht for each i,j. what i need is the value h(j), which does not depend on i. this value should minimize the differences with all the ht values in "i", and i need to repeat this for each i. therefore, the difference ins is not a single value; there will be as many differences as ht values. my objective is not to make the differences between ht and h equal to 0; rather, i want to find the h that minimizes the maximum value of ins across all "i". for example, if i have a matrix ht with the following rows (7,8) and (5,9), i need to find h(1) such that the maximum value between 7-h(1) and 8-h(1) is minimized, and h(2) such that the maximum value between 5-h(2) and 9-h(2) is minimized, with the additional condition that h(2) > h(1).
thanks for the help
function [h] = hp(ht, lc, lt)
lt = 0:0.5:lt;
lc = 0:0.5:lc;
ins = cell(length(lt), length(lc));
h= cell(length(lc));
for i = 1:length(lt)
for j = 1:length(lc)
ins{i,j} = @(h) (ht(i,j) - h);
end
end
h0 = zeros(size(lc));
a = [];
b = [];
aeq = [];
beq = [];
lb = [];
ub = [];
nonlcon = @constraints;
h = fmincon(@(h) ins, h0, a, b, aeq, beq, lb, ub, nonlcon);
end
function [c] = constraints(h)
c>0;
c = h(2:end) - h(1:end-1);
end
jon bilbao
https://ww2.mathworks.cn/matlabcentral/profile/authors/26244395
tag:ww2.mathworks.cn,2005:question/498568
2019-12-31t21:38:15z
2023-06-08t04:31:03z
sysgen license checkout failed.
i am working on xilinx system generator.
i get an error when run my simulink block-
sysgen license checkout failed.
xilinxd_license_file = d:\xilinx\2017_xilinx\xilinx.lic;c:/xilinx/vivado/2017.4/data/sysgen/hwcosim_compiler/pp_ethernet
lm_license_file = xilinx
license search path: c:\users\sandip\appdata\roaming\xilinxlicense;c:\.xilinx;d:\xilinx\2017_xilinx\xilinx.lic;c:\xilinx\vivado\2017.4\data\sysgen\hwcosim_compiler\pp_ethernet;xilinx;c:\xilinx\vivado\2017.4\data\ipcore_licenses
i have already go through the xilinix manage license tab and reset the license path...but still got the error..please solve the error
sandip paul
https://ww2.mathworks.cn/matlabcentral/profile/authors/16932120
tag:ww2.mathworks.cn,2005:question/1979954
2023-06-08t04:19:40z
2023-06-08t04:26:44z
error during gan training : render process terminated: null java.lang.nosuchfielderror: ts_process_oom
the following error occurred during gan training:
error message:
render process terminated: null
java.lang.nosuchfielderror: ts_process_oom
--detailed information--
system: hp z4 workstation, memory: 128gb, ssd: 1tb (50% is available)
operating system: windows 10, 64-bit
matlab version: r2022b
java heap space: 32.697gb
execution file: example file from matlab, traingenerativeadversarialnetwork(gan)example
i think java heat space is enough because the system memory usage is below 20gb and java heap space setting is over 32gb.
please, let me know how to solve this problem.
mo
https://ww2.mathworks.cn/matlabcentral/profile/authors/20190775
tag:ww2.mathworks.cn,2005:question/1979354
2023-06-06t21:17:52z
2023-06-08t04:25:36z
fatal startup error after update 2 of r2023a
i tried to do update 2 of r2023a and the update failed. now i can't open matlab. what can i do? i get this error message:
fatal startup error
dynamic exception type: class cppmicroservices:: sharedlibraryexception
std::exception::what: loading c:\program
files\matlab\r2023a\bin\win64\matlab_startup_plugins\foundation\pl
atform\pf_matlab_impl\libmwpf_matlab_impl.dllfailed with error: the
specified procedure could not be found.
: state not recoverable: state not recoverable
michael lopez
https://ww2.mathworks.cn/matlabcentral/profile/authors/25508317
tag:ww2.mathworks.cn,2005:question/1979554
2023-06-07t08:58:04z
2023-06-08t04:24:49z
higher rank tensor: how to export and read it as a file?
hello,
i have a rank-3 tensor, say simply
tensor=zeros(da,db,dc);
where da, db and dc are the respective dimensions. i like to export it as a file and later on import it again to continue some calculation in another matlab script. how do i do this? as far as i see, dlmwrite, cswwrite and writematrix only work for matrices and give me some error saying "transpose not defined...".
many thanks!
philipp
https://ww2.mathworks.cn/matlabcentral/profile/authors/29742826
tag:ww2.mathworks.cn,2005:question/1976689
2023-06-01t11:33:00z
2023-06-08t04:22:42z
issue with calling a for loop before the sim command.
when i use a for loop just before calling the sim(model) command to simulate a simulink model, i receive this error:
error using error_bucle_rarisimo (line 139)
derivative of state '1' in block 'phasorpvesssmmodel/sg/sm/electrical model/synchronous machine continuous
model/phi/integrator' at time 0.0083 is not finite. the simulation will be stopped. there may be a
singularity in the solution. if not, try reducing the step size (either by reducing the fixed step size
or by tightening the error tolerances)
however, if i simulate before calling the for loop, the error does not appear.
my initial idea was to include the sim command within the loop to simulate the model for different parameters, but i always encountered this error. initially, i thought it was an issue with the parameters i passed to the model, but now i've noticed that simply calling the for loop doesn't work.
i have tried everything, and i'm not sure what could be causing this failure. can anyone help me? thank you very much.
emilio valdivielso suárez
https://ww2.mathworks.cn/matlabcentral/profile/authors/16096490
tag:ww2.mathworks.cn,2005:question/1807035
2022-09-17t09:17:16z
2023-06-08t04:19:38z
correct and incorrect predictors
dear community members, i am stuck in a problem. i tried to search for the solution but i could not find. i want to get the input data (predictors) of an incorrect predicted class. how can i do that? i am just able to get the incorrect classes in the confusion chart but i need to find the input data of them.
for example lets take this example:
load satdata;
pt = cvpartition(satclass,'holdout',0.3);
predtrain = satdata(training(pt),:);
classtrain = satclass(training(pt));
predvalid = satdata(test(pt),:);
classvalid = satclass(test(pt));
knnclassifier = fitcknn(predtrain,classtrain,'numneighbors',5);
ypred = predict(knnclassifier,predvalid);
[c,lbls] = confusionmat(ypred,classvalid);
here i can only see the classes in ypred but i cant see the input data (predictors) of those classes. i hope i am clear to my question.
saeed magsi
https://ww2.mathworks.cn/matlabcentral/profile/authors/19883360
tag:ww2.mathworks.cn,2005:question/1977609
2023-06-03t05:17:35z
2023-06-08t04:13:36z
how to extract data from txt file and plot spectogram?
hello,
i have a large sample of data (100000 samples) in txt file consisting of time and amplitude of the signal.
i want to plot spectogram. the code is not at all able to extract the .txt file at all along the path.
kindly advice me as how to extract data from txt file when data is very large as it is in my case and hence to plot the spectogram.
the code is as below:
close all;
freq_sam = 100000; % samples in tt1 data
period_tt1 = 0.005; % time period
freq_tt1 = 1/period_tt1; % frequency
data = importdata('d:\data_tokamak\data\obp.txt');
x_data = data(:,1);
y_data = data(:,2);
disp(x_data);
disp(y_data);
signal_tt1 = data;
fft_tt1 = fft(signal_tt1); % fourier transform
fft_tt1 = fftshift(fft_tt1); % performing fft shift
f = freq_sam/2*linspace(-1,1,freq_sam);
figure;
plot(f, fft_tt1);
rahul
https://ww2.mathworks.cn/matlabcentral/profile/authors/28962299
tag:ww2.mathworks.cn,2005:question/425129
2018-10-20t20:57:11z
2023-06-08t04:13:09z
how could find the index (number of row ) that are deleted by "deleteoutliers"
i have a table with 9 cells to find the outliers and omit them in each cell, i used the "deleteoutliers" function base on a specific column. but it omits the data just on that specific column, i need to delete all related data to that outliers. how could find the index (number of rows) that are deleted by "delete outliers"?
nooshin mahmoodi
https://ww2.mathworks.cn/matlabcentral/profile/authors/11506464
tag:ww2.mathworks.cn,2005:question/1979479
2023-06-07t07:16:30z
2023-06-08t03:52:48z
processing .mat files via a for loop
hi there,
i would like to read in these .mat files and process them via a for loop
firstly, i need to replace all values above 700 in column 2 (par) with nan
secondly, i need to find all missing datetimes from column 1 (datetime) and fill these in (datetime should be running every 5 min), the corresponding value in column 2 can be nan
i have attempted to create a for loop and believe that the table needs to be converted into a timetable to be able to use greater than (>)?
i am new to for loops, but it would be good to learn how to do all of this processing within the for loop rather than for each separate file.
tia
sophia
https://ww2.mathworks.cn/matlabcentral/profile/authors/24093931
tag:ww2.mathworks.cn,2005:question/1979874
2023-06-07t20:37:58z
2023-06-08t03:51:56z
code generation failed due to unexpected object of type 'rootof'.
hi everyone, i am trying to run the code below, but matlab keeps throwing this error message at me. does anyone know whats the issue?
syms y dy d2y x
k=5/8;
w=100;
q=1;
p=1;
r=0.06;
e=0.5;
a=1/3;
z=0.15;
t=0.9;
s1=2;
m1=0.5;
fstar=4.9259e-16;
b=0.9273;
t1=(1 (z*fstar)/(r t*p*s1-m1))*(2200^((1-k)*(e/(1-e))))*(((1-a)/w*q*a)^(e/(1-e)))*(e/(1-e))*(1/(p*s1 r (1-b)*fstar-m1))^((1-e*(1-a))/((1-a)*(1-e)));
ode = y-((1 (z*fstar)/(r t*p*(dy*x*s1/y)-((dy*x*m1/y) d2y*(x^2)*(s1^2)/(2*y))))*(x^((1-k)*(e/(1-e))))*(((1-a)/w*q*a)^(e/(1-e)))*(e/(1-e))*(1/(r (1-b)*fstar p*(dy*x*s1/y)-((dy*x*m1/y) d2y*(x^2)*(s1^2)/(2*y))))^((1-e*(1-a))/((1-a)*(1-e))));
d2ynum = solve(ode==0,d2y);
d2ynum = d2ynum(3);
f = matlabfunction(d2ynum,"vars",{x, [y dy]});
delaram
https://ww2.mathworks.cn/matlabcentral/profile/authors/30071392
tag:ww2.mathworks.cn,2005:question/492375
2019-11-21t13:44:46z
2023-06-08t03:46:53z
'character vector is not terminated properly' when i am trying to open a .fis file in matlab
i am trying to open my mandami fis which i have saved, and when i try to import it to the fuzzy logic designer i get an error sayinf that the 'character vector is not terminated properly'
does anyone know a solution to this?
ahmed omar
https://ww2.mathworks.cn/matlabcentral/profile/authors/16635088
tag:ww2.mathworks.cn,2005:question/1978609
2023-06-05t14:34:27z
2023-06-08t03:37:30z
eigen value of stochastic matrix
i wan to find eigen values and eigen vector of a stochastic matrix using newton raphson method.
% define the dimensions and variables
n = 3; % size of vectors and matrices
m = 2; % number of matrices
p = 4; % number of eigenvalues and tensors
maxiterations = 100; % maximum number of iterations
tolerance = 1e-6; % tolerance for convergence
% initialize variables
u = ones(n*p, 1); % initial guess for u, each column represents u1, u2, ..., up
lambda = ones(p, 1); % initial guess for lambda, each element represents lambda1, lambda2, ..., lambdap
% define the matrices and tensors
c0 = eye(p); % example: identity matrix
a0 = magic(n); % example: identity matrix
c = rand(p, p, m); % example: random p x p x m tensor
a = rand(n, n, m); % example: random n x n x m tensor
e = rand(p, p, p); % example: random p x p x p tensor
ca=0;
for i=1:m
ca= ca kron(c(:,:,i),a(:,:,i));
end
% perform newton-raphson iteration
for iter = 1:maxiterations
% compute the left-hand side of the equation
lhs = (kron(c0 , a0) ca) * u;
% compute the right-hand side of the equation
lame=0;
for p = 1:p
lame = lame kron(lambda(p) * e(:, :, p),eye(n)) ;
end
rhs=lame*u
% compute the residual and check for convergence
residual_1 = lhs - rhs;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% initialize the variables
i=eye(n,n);
ca1=zeros(p,1);
for i=1:p
ca1(i)= u'*kron(e(:,:,i),i)*u;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
residual_2=ca1;
% compute the residual and check for convergence
residual = [residual_1;residual_2];
if norm(residual(:)) < tolerance
disp('converged!');
break;
end
jacobian = jac_1(a,lambda , u, n,m,p);
% update u and lambda using the newton-raphson method
delta = jacobian \ residual(:);
u = u - delta(1:n*p);
lambda = lambda - delta(n*p 1:end);
% display the current iteration and residual
disp(['iteration: ' num2str(iter) ', residual: ' num2str(norm(residual(:)))]);
end
uf=reshape(u,n,[])
lambdaf=lambda
but the answer i am getting is
lambdaf =
1.0e 58 *
2.7709
-1.9052
0.3483
-0.3253.
it would be very helpful if someone help me improve this code
rakesh kumar
https://ww2.mathworks.cn/matlabcentral/profile/authors/15908659
tag:ww2.mathworks.cn,2005:question/1979684
2023-06-07t13:40:23z
2023-06-08t03:24:54z
find distance of two points inside a matrix
hello everyone! so i have a meshgrid of longitudes and latitudes and an other matrix that gives me the depths corresponding to the same indexes.i want to choose an x1,y1 value and an x2,y2 value and interpolate all the depths in between those to coordinates?how can i do this?
lena kappa
https://ww2.mathworks.cn/matlabcentral/profile/authors/18875207
tag:ww2.mathworks.cn,2005:question/1979949
2023-06-08t03:13:11z
2023-06-08t03:13:11z
how can i interface my texas instrument dsp with available can communication through simulink
hello all,
i have a tif28379d board that is operating an motor drive. there is can interface in the motordrive. is it possible to control the can or establish link through simulink with can and dsp at the same time? the can communication supports national instrument driver.
thanks for the help.
ashik
ashik amin
https://ww2.mathworks.cn/matlabcentral/profile/authors/15796878
tag:ww2.mathworks.cn,2005:question/1571813
2021-10-26t08:06:52z
2023-06-08t02:59:39z
custom class properties and method attributes
is there a way to add custom property or method attributes to handle classes? it is done by several classes or toolboxes, e.g. the unit testing framework allows to add tags to the methods: tag unit tests - matlab & simulink (mathworks.com)
classdef exampletagtest < matlab.unittest.testcase
methods (test)
function testa (testcase)
% test code
end
end
methods (test, testtags = {'unit'})
function testb (testcase)
% test code
end
function testc (testcase)
% test code
end
end
i'm talking about the attributes "test" and "testtags".
my application would greatly benetfit from a finer granular control of properties for a dto (data transfer object) class. i want to use argument validation but add additional options like overridable properties and don't want to use inputparser anymore :)
thanks!
jan kappen
https://ww2.mathworks.cn/matlabcentral/profile/authors/7294693
tag:ww2.mathworks.cn,2005:question/1645380
2022-02-08t09:34:56z
2023-06-08t02:56:39z
java.lang.illegalargumentexception: ntfs ads separator (':') in file name is forbidden
when i perform coder with single precision conversion using fixed point designer, during mex building, following errors happn.but when i perform coder without precision conversion, no error happens. how can i fix this problem?
exception in thread "awt-eventqueue-0": java.lang.illegalargumentexception: ntfs ads separator (':') in file name is forbidden.
at org.apache.commons.io.filenameutils.indexofextension(filenameutils.java:746)
at org.apache.commons.io.filenameutils.getextension(filenameutils.java:1069)
at com.mathworks.toolbox.coder.nide.editor.coderfilebackingstore.(coderfilebackingstore.java:38)
at com.mathworks.toolbox.coder.nide.editor.coderfilebackingstore.(coderfilebackingstore.java:30)
at com.mathworks.toolbox.coder.nide.nideartifactset.addsourceartifact(nideartifactset.java:69)
at com.mathworks.toolbox.coder.nide.impl.codernidefacade.updateartifactset(codernidefacade.java:339)
at com.mathworks.toolbox.coder.nide.impl.codernidefacade.initfilestomodel(codernidefacade.java:304)
at com.mathworks.toolbox.coder.nide.impl.codernidefacade.access$800(codernidefacade.java:63)
at com.mathworks.toolbox.coder.nide.impl.codernidefacade$4.propertychange(codernidefacade.java:207)
at java.beans.propertychangesupport.fire(propertychangesupport.java:335)
at java.beans.propertychangesupport.firepropertychange(propertychangesupport.java:327)
at java.beans.propertychangesupport.firepropertychange(propertychangesupport.java:263)
at com.mathworks.toolbox.coder.nide.impl.codernideappmodel.fireinputfileschanged(codernideappmodel.java:175)
at com.mathworks.toolbox.coder.nide.impl.codernideappmodel.setinputfiles(codernideappmodel.java:171)
at com.mathworks.toolbox.coder.wfa.build.verifycompatibilitymodel$normalmexbuilder$1.handlefiles(verifycompatibilitymodel.java:534)
at com.mathworks.toolbox.coder.wfa.build.coderbuildmanager$handler$1.run(coderbuildmanager.java:250)
at com.mathworks.mwswing.mjutilities.runoneventdispatchthread(mjutilities.java:911)
at com.mathworks.toolbox.coder.wfa.build.coderbuildmanager$handler.buildfinished(coderbuildmanager.java:247)
at com.mathworks.toolbox.coder.wfa.build.buildcommand$1$1.run(buildcommand.java:211)
at java.awt.event.invocationevent.dispatch(invocationevent.java:311)
at java.awt.eventqueue.dispatcheventimpl(eventqueue.java:758)
at java.awt.eventqueue.access$500(eventqueue.java:97)
at java.awt.eventqueue$3.run(eventqueue.java:709)
at java.awt.eventqueue$3.run(eventqueue.java:703)
at java.security.accesscontroller.doprivileged(native method)
at java.security.protectiondomain$javasecurityaccessimpl.dointersectionprivilege(protectiondomain.java:74)
at java.awt.eventqueue.dispatchevent(eventqueue.java:728)
at java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:205)
at java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:116)
at java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:105)
at java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:101)
at java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:93)
at java.awt.eventdispatchthread.run(eventdispatchthread.java:82)
adelie penguin
https://ww2.mathworks.cn/matlabcentral/profile/authors/19968904
tag:ww2.mathworks.cn,2005:question/1976614
2023-06-01t08:37:55z
2023-06-08t02:45:20z
how can i add a listener to an axe to check everytime the amount of curves is changed. event childadded works, but event childremoved seem to not work.
hi all,
i'm creating an app where an user get to load a picture of a graph (like from a scientific text book) and run a script so that he can obtain the data on the picture, i.e. adding a grid and the value of the grid, a value in pixel within the picture transform into a value within the axes of the graph. the user can then "select the position of the curve of interest" in the picture (using ginput) and the program transfer the line thus created into a line with the values as in the picture. (hope i'm being clear). as an example:
you have a picture of a graph showing the evolution of the population of deer in a forest over time. this picture when loaded into matlab would be referenced by a number of pixels. but on those pixels, the user can see that the x-axis is in unit months and the y-axis in thousand of deer. building a grid at each value of both axis, it is then possible, for example, to put an equivalence between pixel (340, 240) and the value (may 2022/15'500) and the pixel (350,210) to the value (june 2022/12500) (hypothetical value..there has not been a massive death of deer in the forest within may :))
i have all the functions i need to make this app works but i wanted to build it "stupid proof" such that an user cannot mess up the app. one aspect i wanted to ensure was that any deletion of a curve would be traced through all the functions. so that i don't get a mistmatch between the amount of curves seen in the plot in "pixel value", and the amount of data registered in "time/deer" value.
i wanted then to add a listener to the "children" of the axes so that whenever the amount of children change, the change can be capture by the other functions as well.
however, the property children of axes is not setobservable. so i cannot put a listener on this.
by browsing internet, i found out that there are "hidden" events in the class matlab.graphics.axis.axes:
m = ?matlab.graphics.axis.axes;
e = m.eventlist;
among this list, there are two events called "childadded" and "childremoved".
i do manage to make a listener to the "childadded" event, but it seems that the "childremoved" does not work, making my "stupid proof" not usable as the user would still be capable of deleting curves without the code knowing about it.
do you have any idea as to how i could solve this lack of "observability" of events linked with deletion of lines in a axes?
bastien haemmerli
https://ww2.mathworks.cn/matlabcentral/profile/authors/6160037
tag:ww2.mathworks.cn,2005:question/1975644
2023-05-30t13:00:03z
2023-06-08t02:42:00z
question regarding plotting a map consisting of different layers
hello,
using matlab mapping toolbox, i want to plot a map (baltic sea region, to be specific) which has three different layers in shapefile format, i.e. coastline, bathymetry, and land. however it doesn't work so far.
here is the code:
% load shapefile data
balticsea.coast = shaperead('ne_10m_coastline.shp');
balticsea.land = shaperead('ne_10m_land.shp');
balticsea.bathym = shaperead('ne_10m_bathymetry.shp')
% create a figure
figure
mapshow(balticsea.coast)
mapshow(balticsea.land)
mapshow(balticsea.bathym)
is there any ways to solve this?
thank you.
dipto
https://ww2.mathworks.cn/matlabcentral/profile/authors/29350672
tag:ww2.mathworks.cn,2005:question/1979924
2023-06-08t00:43:50z
2023-06-08t02:33:27z
updating tiledlayout in a loop - "invalid or deleted object"
hello, i am trying to write a program that creates a gif of a 3d trajectory (t, x, y, z coordinate data in file xxxy.mat) from 4 different perspectives. however, i keep getting the classic "invalid or deleted object" error when i first try to alter the tile axes in the plotting loop. the code is pasted below and any help is appreciated.
clear;clc;
load('xxxy.mat')
%%
% create file name variable
filename = 'animation_spiral_3pov.gif';
% setting up the plot
l = tiledlayout(2,2);
title(l,sprintf('trajectory\ntime: %0.2f sec', t(1)),...
'interpreter','latex');
%%
% plotting the first iterations
nexttile(1)
p1 = plot(-xx(1),-xy(1),'b');
m1 = scatter(-xx(1),-xy(1),'filled','b');
grid on % adding grid lines
axis equal % equal axis aspect ratio
xlim([-5 5])
ylim([-5 5])
hold on
title('top view', 'interpreter', 'latex')
nexttile(2)
p2 = plot(-xy(1),xz(1),'b');
m2 = scatter(-xy(1),xz(1),'filled','b');
grid on % adding grid lines
axis equal % equal axis aspect ratio
xlim([-5 5])
ylim([-5 5])
hold on
title('side view', 'interpreter', 'latex')
nexttile(3)
p3 = plot(-xx(1),xz(1),'b');
m3 = scatter(-xx(1),xz(1),'filled','b');
grid on % adding grid lines
axis equal % equal axis aspect ratio
xlim([-5 5])
ylim([-5 5])
hold on
title('front view', 'interpreter', 'latex')
nexttile(4)
p = plot3(xx(1),xy(1),xz(1),'b');
m = scatter3(xx(1),xy(1),xz(1),'filled','b');
grid on % adding grid lines
axis equal % equal axis aspect ratio
xlim([-5 5])
ylim([-5 5])
zlim([-5 5])
view(-170,15); % setting viewing angle
hold on
title('3d view', 'interpreter', 'latex')
%%
% iterating through the length of the time array
for k = 1:200:length(t)
% updating the line (p) and scatter points (m)
nexttile(l,1)
p1.xdata = -xx(1:k);
p1.ydata = -xy(1:k);
m1.xdata = -xx(k);
m1.ydata = -xy(k);
nexttile(l,2)
p2.xdata = -xy(1:k);
p2.ydata = xz(1:k);
m2.xdata = -xy(k);
m2.ydata = xz(k);
nexttile(l,3)
p3.xdata = -xx(1:k);
p3.ydata = xz(1:k);
m3.xdata = -xx(k);
m3.ydata = xz(k);
nexttile(l,4)
p.xdata = xx(1:k);
p.ydata = xy(1:k);
p.zdata = xz(1:k);
m.xdata = xx(k);
m.ydata = xy(k);
m.zdata = xz(k);
% updating the title
title(l,sprintf('trajectory\ntime: %0.2f sec', t(k)),...
'interpreter','latex');
% delay
pause(0.1)
% saving the figure
frame = getframe(gcf);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
if k == 1
imwrite(imind,cm,filename,'gif', 'loopcount',inf,...
'delaytime',0.1);
else
imwrite(imind,cm,filename,'gif','writemode','append',...
'delaytime',0.1);
end
end
ian heyman
https://ww2.mathworks.cn/matlabcentral/profile/authors/8694624
tag:ww2.mathworks.cn,2005:question/1979939
2023-06-08t02:32:23z
2023-06-08t02:32:23z
visadev autoly continously send '*idn?'. get thousands of lines of the return of '*idn?'
i have a optical spetrum whose name is ando aq6317. after use ni gpib-usb-hs connect it with my windows server, with matlab 2021b and a package of i"nstrument control toolbox support package for national instruments visa and icp interfaces 21.2.1".
i use the v = visadev('gpib0::1::0::instr')
can successfully coonect.
but the problem is, the device will repeatedly send the instrument info string. with thousands of lines, times. the content is the same as the querying output of "*idn?".
and i can see the v.numbytesavailable exponentially surge. within the time i did nothing.
i use read(v,v.numbytesavailable,"char") to watch and everything is the querying output of '*idn?'
so i really doubt that the visadev has a bug of autoly continously send '*idn?'.
other instruments like keysight awg 8194 i tried, tek osc or awg will not occur this problem.
how to do???
although i found use old method g1=gpib('ni',0, 1);
can avoid the bug. but i do not wanna write two type of visa codes. for my previous codes are all based on visadev!!!!!!!!!!!!
long
https://ww2.mathworks.cn/matlabcentral/profile/authors/14345967
tag:ww2.mathworks.cn,2005:question/1979934
2023-06-08t02:17:47z
2023-06-08t02:17:47z
is it possible to make windows desktop pc to a master host for ethercat network?
i want to control 3 actuators (orientalmotor) using an orientalmotor multi-axis driver that works with ethercat, and i'm trying to make a hils approach using simulink.
for this case, i was thinking on using a speedgoat device as slave.
my question lies in how can i make my desktop pc into a master device that runs with ethercat network in order to control these actuators?
giancarlo guerra padilla
https://ww2.mathworks.cn/matlabcentral/profile/authors/25995462
tag:ww2.mathworks.cn,2005:question/1979399
2023-06-07t00:49:26z
2023-06-08t02:15:32z
how can i get datacursor information from scatter plot using a callback function in app designer
hello,
in app designer, i'm trying to implement a functionality where i would click on a data point in a scatter plot and that would trigger the generation of a new plot related specifically to that selected point. currently i was able to turn the datacrusor mode on and select different data points by clicking on the plot. what i'm trying to achieve now is that when i click on a point i can obtain the information of which point has beeen selected through the data crusor then generate a new figure. i have tried to implement a buttondown call back funtion but i wasnt able to get anywhere with that. can anyone please assist me with that?
thank you,
ahmed,
ahmed
https://ww2.mathworks.cn/matlabcentral/profile/authors/30175813
tag:ww2.mathworks.cn,2005:question/1978344
2023-06-05t08:33:07z
2023-06-08t02:10:29z
how can i find the elapsed time between two images from video file with matlab.
how can i find the elapsed time between two images from video file with matlab.
i drop a drop of water on a surface. i want to find the water absorption time of the surface from the video i recorded with matlab. can you help me? i don't know much about matlab.
bykado
https://ww2.mathworks.cn/matlabcentral/profile/authors/17024042
tag:ww2.mathworks.cn,2005:question/1979519
2023-06-07t00:00:00z
2023-06-08t02:09:18z
how to generate code with pointcloud select in matlab coder
though i read the following manual of 'select', it just mentioned "the input argument outputsize must be compile-time constant." under the code generation.
https://www.mathworks.com/help/releases/r2023a/vision/ref/pointcloud.select.html
i would like to know how to apply the input argument outputsize to be in compile-time constant in order to generate code.
mathworks support team
https://ww2.mathworks.cn/matlabcentral/profile/authors/4622813
tag:ww2.mathworks.cn,2005:question/368689
2017-11-22t20:55:55z
2023-06-08t01:20:40z
how to define a custom equation in fitlm function for linear regression?
i'd like to define a custom equation for linear regression. for example y = a*log(x1) b*x2^2 c*x3 k. this is a linear regression problem - but how to do this within fitlm function?
thanks,
shriram
spirit
https://ww2.mathworks.cn/matlabcentral/profile/authors/3264447
tag:ww2.mathworks.cn,2005:question/1978564
2023-06-05t13:46:29z
2023-06-08t01:05:37z
multioutput regression models in matlab
i am working on a project where i need to predict multiple response variables for a given data set likely using random forests or boositng. are there any functions i could use that might provide what i am looking for. basically, what i mean is:
data = (2-d matrix of regressors)
regression model = regression_function(data,response variables)
alejandro plata
https://ww2.mathworks.cn/matlabcentral/profile/authors/25363631
tag:ww2.mathworks.cn,2005:question/1979904
2023-06-07t22:18:04z
2023-06-08t00:58:43z
i'm getting weird units while double-integrating accelerometer data to extract displacement
i'm currently working on a research project, where we are trying to measure how much test subjects move their head while looking at pictures under different conditions. we are using an accelerometer attached to their head on a hat, and the head movements are meant to be very slight (only moving about an inch side-to-side). we recorded a few test trials just to see what the data looks like, and this is the script i wrote to get average displacement out of it:
clc, clearvars
hat_on_table = readtable('hat_on_table.csv');
looking_at_screen = readtable('looking_at_screen.csv');
talking = readtable('talking.csv');
walking = readtable('walking.csv');
avg_displacements = {func(hat_on_table), func(looking_at_screen),func(talking), func(walking)}
column_names = {'hat_on_table', 'looking_at_screen', 'talking', 'walking'};
data_table = cell2table(avg_displacements, 'variablenames', column_names, 'rownames', {'average displacement (m)'});
function avg_displacement = func(curr)
time = curr.('epoc_ms_');
time = time - time(1);
% convert from ms to s
time = time / 1000;
acc_x = curr.('x_axis_g_');
acc_y = curr.('y_axis_g_');
acc_z = curr.('z_axis_g_');
% convert from gs to m/s^2
acc_x = acc_x*9.80665;
acc_y = acc_y*9.80665;
acc_z = acc_z*9.80665;
% find displacement for each axis
% normalize the data
acc_x = acc_x - mean(acc_x);
time_and_acc_x = table(time, acc_x, 'variablenames', {'time (s)', 'x-axis acceleration m/s^2'});
% integrate first for velocity (m/s), then again for displacement (m)
velocity_x = cumtrapz(time_and_acc_x.("time (s)"), time_and_acc_x.('x-axis acceleration m/s^2'));
displacement_x = cumtrapz(time_and_acc_x.("time (s)"), velocity_x);
% normalize the data
acc_y = acc_y - mean(acc_y);
time_and_acc_y = table(time, acc_y, 'variablenames', {'time (s)', 'y-axis acceleration m/s^2'})
% integrate first for velocity (m/s), then again for displacement (m)
velocity_y = cumtrapz(time_and_acc_y.("time (s)"),time_and_acc_y.('y-axis acceleration m/s^2'));
displacement_y = cumtrapz(time_and_acc_y.("time (s)"), velocity_y);
% normalize the data
acc_z = acc_z - mean(acc_z);
time_and_acc_z = table(time, acc_z, 'variablenames', {'time (s)', 'z-axis acceleration m/s^2'});
% integrate first for velocity (m/s), then again for displacement (m)
velocity_z = cumtrapz(time_and_acc_z.("time (s)"), time_and_acc_z.('z-axis acceleration m/s^2'));
displacement_z = cumtrapz(time_and_acc_z.("time (s)"), velocity_z);
% combine the three axes into one displacement value
total_displacements = sqrt((displacement_x.^2) (displacement_y.^2) (displacement_z.^2));
avg_displacement = mean(total_displacements)
end
the issue is that the numbers which we get for average displacements do not make sense for the conditions under which we recorded. just leaving the hat completely still on the table translated to an average displacement of 3.9m, and looking at a laptop screen resulted in an average displacement of 87.7m. are the units wrong? or have i messed up somewhere while integrating/combining the data? does it need to be filtered first? (due to the small nature in the desired behavior, i thought filtering could lose the meaningful differences).
any direction would be much appreciated!
nathaniel
https://ww2.mathworks.cn/matlabcentral/profile/authors/30216438
tag:ww2.mathworks.cn,2005:question/1977014
2023-06-01t19:40:24z
2023-06-08t00:51:59z
how to make a surface in polar coordinates using polar3d?
hello! i have an integral for a function which i plot in polar coordinates at a fixed polar angle theta (th). how to write a 3d plot for r in polar coordinates (angles a and th changes)? i made it using pol2cart, but this is not the best way to present the result. if somebody can help me to plot using polar3d or something like this, it would be great. thank you.
clear all
s = 3;
n = 1;
r = 1;
t = 0.1;
th = 0:10:360; % angle theta
a = 0:1:360; % angle alpha
b = sqrt(2*n*t);
l = sqrt((4*t r^2)/3);
fun = @(k,u,c,a) ((k.^2).*exp(-1.5*k.^2)).*((u.^2).*(1-u.^2).*exp(-(b.*u).^2).*(cos(s.*k.*u.*cos(a)/l))).*(((cos(c)).^2).*(cos(k.*sqrt(1-u.^2).*(s.*sin(a).*cos(th).*cos(c) s.*sin(a).*sin(th).*sin(c))/(l))));
f3 = arrayfun(@(a)integral3(@(k,u,c)fun(k,u,c,a),0,inf,-1,1,0,2*pi),a);
b = ((6*sqrt(6)*(b^3))/(erf(b)*(pi^2)))*(1-(3/(2*b^2))*(1-((2*b*exp(-b^2))/(erf(b)*sqrt(pi)))))^(-1);
r = b*f3;
figure(3)
polar(a,r);
this is how it look in cartesian coordinates (theta in radians), but it should look much better in polar3d.
hexe
https://ww2.mathworks.cn/matlabcentral/profile/authors/28003261
tag:ww2.mathworks.cn,2005:question/1979859
2023-06-07t19:38:09z
2023-06-08t00:17:23z
constrain the csapi fitting to positive values
i have a vector x of size 25 x 1 and a vector y of size 25 x 1. i subject them to spline fitting function (as below) and i get a function whose values go in the negative range. i know apriori that the values should be positive. is there any method to constrain the fitting according to this using csapi?
cs = csapi(x,y); % vectors of size 25 x 1
figure(11)
fnplt(cs,2);
hold on
plot(x,y,'o')
hold off
xlabel('pixel values from the intensity patch')
ylabel('pixel values from the ir patch')
areeba fatima
https://ww2.mathworks.cn/matlabcentral/profile/authors/16946717
tag:ww2.mathworks.cn,2005:question/1979914
2023-06-07t23:57:06z
2023-06-07t23:57:06z
matlab coder returning non specific issue description during check for runtime issues step
hello,
for use in a student project, i am attempting to convert an audio-based transmitter/receiver function from matlab to c/cpp.
i went through the process of correcting various issues, brought up by the matlab coder tool.
however, the latest issue brought up by the "check for run-time issues" step does not mention any line / sub-function in the code. instead, it simply states:
" insufficient number of outputs from right hand side of equal sign to satisfy assignment.
use help codegen for more information on using this command.
insufficient number of outputs from right hand side of equal sign to satisfy assignment."
i do not know where in the code this issue is located, and given the project size, i would prefer not to start looking with no clear leads.
the function i am trying to convert is running correctly, and no issues are found before the runtime issues check (input types, %#codegen, etc.).
any help in accessing a more detailed error message / pointing me in the right direction would be greatly appreciated.
thanks (:
jonathan
jonathan elgavi
https://ww2.mathworks.cn/matlabcentral/profile/authors/17906028
tag:ww2.mathworks.cn,2005:question/1979369
2023-06-06t23:02:57z
2023-06-07t23:56:27z
unable to locate and load .mat file after compiled into standalone file in app designer
hello community and team,
i am new to app design and recently created an app using app designer.
my app includes two additional files. the first one is a .mat file that contains a simfun (with no parallel turned on) and a dosetable. the second file is a class used to solve my equation.
the app runs flawlessly in the app designer ui, but when i compile it into a standalone app, it always gets stuck at the simulation part. it seems that the compiled app cannot find and load the .mat file.
i have done some research on the isdeployed function, but none of the solutions i found could solve my problem and how could i locate the .mat file if i don’t know the path of the file in the app?
interestingly, when i compiled the app on my macbook pro 15-inch 2016, it didn't work properly. however, when i used my friend's mac mini 2021 m1, the compiled app worked without any issues. both computers have matlab 2023a installed.
i have been frustrated as i couldn't solve this problem for a few days.
could anyone provide me with some suggestions or advice regarding this situation?
thank you very much.
jesse
jesse chao
https://ww2.mathworks.cn/matlabcentral/profile/authors/19346793
tag:ww2.mathworks.cn,2005:question/1957029
2023-05-03t04:50:47z
2023-06-07t23:41:59z
symbolic equation system - hi! can someone please tell me why this algortim is not working? i know resultant values for xa and t are 0.2 and 657 but i want it to work.
i have to mention that ec2 value type is symfalse, i think the code not working has to do with that but i don't know how to solve it.
cpa=14.5;
cpr=12.4;
cps=7.2;
dhr=5665;
r=1.987;
h=-90820/r;
t=31.6;
syms xa t
ec1=0==cpa*(25-672) dhr*xa/4 xa*cpr*(t-25)/4 3*xa*cps*(t-25)/2 (1-xa)*cpa*(t-25);
ec2=t*1.052*10^19==int(1./exp(h./t)./(1-xa),xa,0,xa);
vpasolve(ec1,ec2,xa)
marco antonio pérez castillo
https://ww2.mathworks.cn/matlabcentral/profile/authors/19861928
tag:ww2.mathworks.cn,2005:question/1979909
2023-06-07t23:29:08z
2023-06-07t23:31:42z
how do i add a unique id to the the graph in can explorer in the vehicle network toolbox?
hello! i pulled some can data into vehicle network toolbox/can explorer and was hoping to be able to visualize it using the graph. i found a video on how to add a signal to the graph but it involved having a dbc file (and i didn't see an example document/format of how i would create said dbc file). is there a way to add a signal to the graph any other way? i tried going through the menus and couldn't find a way to do it and dragging/dropping, and right clicking don't seem to get me anywhere either.
any info on how i can take a signal and add it to a graph would be greatly appreciated. if there's not an easy way to do so (that might be a feature request at that point), is there an example dbc format or can i see an example if i wanted to add, say, signals with ids for 0x18d, 0x224, and 0x27a (i have a bunch i want to add but once i see an example, i can put one together myself)? thanks!
jeremy
https://ww2.mathworks.cn/matlabcentral/profile/authors/29463111
tag:ww2.mathworks.cn,2005:question/1979689
2023-06-07t13:41:49z
2023-06-07t23:19:56z
formulating a part of a given circle
i want to create bumps in matlab by providing only two inputs (h=61, l=293.69) as shown in the picture. however, for this i need to formulate the parts that appear in the picture (blue and orange). i know these parts are formulatable because they are all actually part of a circle. but i don't know which circle to associate these blue and orange parts with and how to connect h and l.
any thoughts?
thanks.
raj
https://ww2.mathworks.cn/matlabcentral/profile/authors/30344844
tag:ww2.mathworks.cn,2005:question/1979379
2023-06-06t23:35:23z
2023-06-07t22:43:11z
remove falsely detected foreground (image segmentation)
hi,
i am working on moving object detection in video compressed domain. i have extracted compressed domain features from vvc reference software to create an image(frame).
however, the extracted image falsely detects some part of the background as foreground. for example, in a paragliding video, due to the movement of the camera the slightly changing background(trees) is also beaing detected as foreground. i want to eliminate that part and just have the segmentated image of the person in the parachute. as shown in 0001.png.
the orginal image, extracted image, binary image, morphologically closed image are as follows:
i used yanqi liu's code from: https://www.mathworks.com/matlabcentral/answers/1565216-how-to-remove-unwanted-portion-from-background as part of the process.
it seems to be the right way to go since it gets rid of the unwanted trees but for some reason the paragliding person is not fully detected.
i tried to change the value for the length in strel in imopen from 9 to 10, 12, 16, etc. but it gives me an error
bw = imopen(bw, strel('line', 9, 90));
error using ~=
matrix dimensions must agree.
error in imseg_y (line 61)
bw(l~=ind) = 0;
i even tried to change the value for
bw = bwareaopen(bw, 100);
i changed it 500, 250, etc. i get the same error as above, no matter what value i choose.
can anyone please help correctly detect the foreground while removing the falsely detected foreground?
looking forward to everyone's suggestions! :)
p.s. i have attached my code for reference.
yousra ashfaq
https://ww2.mathworks.cn/matlabcentral/profile/authors/18392559
tag:ww2.mathworks.cn,2005:question/1979894
2023-06-07t21:51:14z
2023-06-07t22:31:16z
setting up graphic user interface
as i have never set up a gui interface i am trying to find out how to do all the call backs correctly. i have included the program i wrote in script editor and the gui code program and a screen shot of the design of the gui. my question is can the radio buttons be used with the code i wrote in editor with all the different loops that i have and if so how do i do that code? if the radio buttons can not work that way is there a better choice?
%program in editor
clear
clc
f=input('gasoline or diesel: ','s');
c=input('number of engine cylinders ');
t=input('trailer being towed yes or no: ','s');
tw=input('trailer weight ');
m=input('trip length in miles ');
c=input('cost of fuel per gallon ');
switch f
case 'gasoline'
if c==4
bmpg=24;
switch t
case 'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.2);
elseif tw>2000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=24;
end
elseif c==6
bmpg=18;
switch t
case 'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.1);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.2);
elseif tw>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=18;
end
elseif c==8
bmpg=12;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.05);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.1);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.2);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.4);
elseif tw>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=12;
end
end
case 'diesel'
if c==4
bmpg=26;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.05);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.1);
elseif tw>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=26;
end
elseif c==6
bmpg=22;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.025);
elseif tw>2000 && tw<=4000
mpg=bmpg-(mbpg*0.5);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.1);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.2);
elseif tw>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=22;
end
elseif c==8
bmpg=18;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.0125);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.05);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.2);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.4);
elseif tw>8000 && tw<10000
mpg=bmpg-(bmpg*0.6);
elseif tw>10000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=18;
end
end
end
fprintf('miles per gallon')
disp(mpg)
g=(m/mpg);%%how many gallons used
fprintf('how many gallons of fuel used')
disp(g)
cf=g*c;%%cost to fuel up
fprintf('cost to fuel up')
disp(cf)
cm=(g/m)*c;%%cost per mile
fprintf('cost per mile')
disp(cm)
x=cf:1:cm;
y=bmpg:1:mpg;
%gui program
classdef jonpagelsprojectgui < matlab.apps.appbase
% properties that correspond to app components
properties (access = public)
uifigure matlab.ui.figure
gridlayout matlab.ui.container.gridlayout
leftpanel matlab.ui.container.panel
editfield matlab.ui.control.numericeditfield
numberofenginecylindersbuttongroup matlab.ui.container.buttongroup
button_8 matlab.ui.control.radiobutton
button_6 matlab.ui.control.radiobutton
button_4 matlab.ui.control.radiobutton
trailertowedbuttongroup matlab.ui.container.buttongroup
nobutton matlab.ui.control.radiobutton
yesbutton matlab.ui.control.radiobutton
fueltypebuttongroup matlab.ui.container.buttongroup
dieselbutton matlab.ui.control.radiobutton
gasolinebutton matlab.ui.control.radiobutton
tripinmileseditfield matlab.ui.control.numericeditfield
tripinmileseditfieldlabel matlab.ui.control.label
trailerweighteditfield matlab.ui.control.numericeditfield
trailerweighteditfieldlabel matlab.ui.control.label
costpergallonslider matlab.ui.control.slider
costpergallonsliderlabel matlab.ui.control.label
centerpanel matlab.ui.container.panel
plotbutton matlab.ui.control.button
calculatebutton matlab.ui.control.button
rightpanel matlab.ui.container.panel
costmileeditfield matlab.ui.control.numericeditfield
costmileeditfieldlabel matlab.ui.control.label
costtofuelupeditfield matlab.ui.control.numericeditfield
costtofuelupeditfieldlabel matlab.ui.control.label
gallonsofusedfueleditfield matlab.ui.control.numericeditfield
gallonsofusedfueleditfieldlabel matlab.ui.control.label
milesgalloneditfield matlab.ui.control.numericeditfield
milesgalloneditfieldlabel matlab.ui.control.label
uiaxes matlab.ui.control.uiaxes
end
% properties that correspond to apps with auto-reflow
properties (access = private)
onepanelwidth = 576;
twopanelwidth = 768;
end
% callbacks that handle component events
methods (access = private)
% value changed function: costpergallonslider
function costpergallonslidervaluechanged(app, event)
c = app.costpergallonslider.value;
app.editfield.value=c;
end
% selection changed function: fueltypebuttongroup
function fueltypebuttongroupselectionchanged(app, event)
f=app.fueltypebuttongroup.selectedobject;
switch f
case app.gasolinebutton
case app.dieselbutton
end
end
% selection changed function: numberofenginecylindersbuttongroup
function numberofenginecylindersbuttongroupselectionchanged(app, event)
c = app.numberofenginecylindersbuttongroup.selectedobject;
switch c
case app.button_4
case app.button_6
case app.button_8
end
end
% value changed function: trailerweighteditfield
function trailerweighteditfieldvaluechanged(app, event)
tw = app.trailerweighteditfield.value;
end
% value changed function: tripinmileseditfield
function tripinmileseditfieldvaluechanged(app, event)
m = app.tripinmileseditfield.value;
end
% button pushed function: calculatebutton
function calculatebuttonpushed(app, event)
m = app.tripinmileseditfield.value;
tw = app.trailerweighteditfield.value;
f=app.fueltypebuttongroup.selectedobject;
t = app.trailertowedbuttongroup.selectedobject;
switch f
case 'gasoline'
case c==4
bmpg=24;
switch t
case 'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.2);
elseif tw>2000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=24;
end
case c==6
bmpg=18;
switch t
case 'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.1);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.2);
elseif tw>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=18;
end
case c==8
bmpg=12;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.05);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.1);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.2);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.4);
elseif tw>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=12;
end
end
case 'diesel'
case c==4
bmpg=26;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.05);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.1);
elseif tw>4000
fprintf('exceedes truck weight limit ');
end
case 'no'
mpg=26;
end
case c==6
bmpg=22;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.025);
elseif tw>2000 && tw<=4000
mpg=bmpg-(mbpg*0.5);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.1);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.2);
elseif tw>8000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=22;
end
case c==8
bmpg=18;
switch t
case'yes'
if tw<=2000
mpg=bmpg-(bmpg*0.0125);
elseif tw>2000 && tw<=4000
mpg=bmpg-(bmpg*0.05);
elseif tw>4000 && tw<=6000
mpg=bmpg-(bmpg*0.2);
elseif tw>6000 && tw<=8000
mpg=bmpg-(bmpg*0.4);
elseif tw>8000 && tw<10000
mpg=bmpg-(bmpg*0.6);
elseif tw>10000
fprintf('exceedes truck weight limit ');
end
case'no'
mpg=18;
end
end
end
app.milesgalloneditfield.value=mpg;
app.gallonsofusedfueleditfield.value=g;
app.costmileeditfield.value=cm;
app.costtofuelupeditfield.value=cf;
end
% selection changed function: trailertowedbuttongroup
function trailertowedbuttongroupselectionchanged(app, event)
t = app.trailertowedbuttongroup.selectedobject;
switch t
case app.yesbutton
case app.nobutton
end
end
% value changed function: milesgalloneditfield
function milesgalloneditfieldvaluechanged(app, event)
app.milesgalloneditfield.value=mpg;
end
% value changed function: gallonsofusedfueleditfield
function gallonsofusedfueleditfieldvaluechanged(app, event)
app.gallonsofusedfueleditfield.value=g;
end
% value changed function: costtofuelupeditfield
function costtofuelupeditfieldvaluechanged(app, event)
app.costtofuelupeditfield.value=cf;
end
% value changed function: costmileeditfield
function costmileeditfieldvaluechanged(app, event)
app.costmileeditfield.value=cm;
end
% changes arrangement of the app based on uifigure width
function updateapplayout(app, event)
currentfigurewidth = app.uifigure.position(3);
if(currentfigurewidth <= app.onepanelwidth)
% change to a 3x1 grid
app.gridlayout.rowheight = {517, 517, 517};
app.gridlayout.columnwidth = {'1x'};
app.centerpanel.layout.row = 1;
app.centerpanel.layout.column = 1;
app.leftpanel.layout.row = 2;
app.leftpanel.layout.column = 1;
app.rightpanel.layout.row = 3;
app.rightpanel.layout.column = 1;
elseif (currentfigurewidth > app.onepanelwidth && currentfigurewidth <= app.twopanelwidth)
% change to a 2x2 grid
app.gridlayout.rowheight = {517, 517};
app.gridlayout.columnwidth = {'1x', '1x'};
app.centerpanel.layout.row = 1;
app.centerpanel.layout.column = [1,2];
app.leftpanel.layout.row = 2;
app.leftpanel.layout.column = 1;
app.rightpanel.layout.row = 2;
app.rightpanel.layout.column = 2;
else
% change to a 1x3 grid
app.gridlayout.rowheight = {'1x'};
app.gridlayout.columnwidth = {475, '1x', 378};
app.leftpanel.layout.row = 1;
app.leftpanel.layout.column = 1;
app.centerpanel.layout.row = 1;
app.centerpanel.layout.column = 2;
app.rightpanel.layout.row = 1;
app.rightpanel.layout.column = 3;
end
end
end
% component initialization
methods (access = private)
% create uifigure and components
function createcomponents(app)
% create uifigure and hide until all components are created
app.uifigure = uifigure('visible', 'off');
app.uifigure.autoresizechildren = 'off';
app.uifigure.position = [100 100 970 517];
app.uifigure.name = 'matlab app';
app.uifigure.sizechangedfcn = createcallbackfcn(app, @updateapplayout, true);
% create gridlayout
app.gridlayout = uigridlayout(app.uifigure);
app.gridlayout.columnwidth = {475, '1x', 378};
app.gridlayout.rowheight = {'1x'};
app.gridlayout.columnspacing = 0;
app.gridlayout.rowspacing = 0;
app.gridlayout.padding = [0 0 0 0];
app.gridlayout.scrollable = 'on';
% create leftpanel
app.leftpanel = uipanel(app.gridlayout);
app.leftpanel.foregroundcolor = [1 0 0];
app.leftpanel.backgroundcolor = [0.8 0.8 0.8];
app.leftpanel.layout.row = 1;
app.leftpanel.layout.column = 1;
% create costpergallonsliderlabel
app.costpergallonsliderlabel = uilabel(app.leftpanel);
app.costpergallonsliderlabel.horizontalalignment = 'right';
app.costpergallonsliderlabel.fontcolor = [1 0.4118 0.1608];
app.costpergallonsliderlabel.position = [5 39 83 22];
app.costpergallonsliderlabel.text = 'cost per gallon';
% create costpergallonslider
app.costpergallonslider = uislider(app.leftpanel);
app.costpergallonslider.limits = [2 7.5];
app.costpergallonslider.majorticks = [2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5];
app.costpergallonslider.valuechangedfcn = createcallbackfcn(app, @costpergallonslidervaluechanged, true);
app.costpergallonslider.fontcolor = [1 0.4118 0.1608];
app.costpergallonslider.position = [109 48 352 3];
app.costpergallonslider.value = 2;
% create trailerweighteditfieldlabel
app.trailerweighteditfieldlabel = uilabel(app.leftpanel);
app.trailerweighteditfieldlabel.horizontalalignment = 'right';
app.trailerweighteditfieldlabel.fontcolor = [0.6353 0.0784 0.1843];
app.trailerweighteditfieldlabel.position = [5 176 79 22];
app.trailerweighteditfieldlabel.text = 'trailer weight';
% create trailerweighteditfield
app.trailerweighteditfield = uieditfield(app.leftpanel, 'numeric');
app.trailerweighteditfield.limits = [0 12000];
app.trailerweighteditfield.valuedisplayformat = '%.0f';
app.trailerweighteditfield.valuechangedfcn = createcallbackfcn(app, @trailerweighteditfieldvaluechanged, true);
app.trailerweighteditfield.fontcolor = [0.6353 0.0784 0.1843];
app.trailerweighteditfield.position = [99 176 100 22];
% create tripinmileseditfieldlabel
app.tripinmileseditfieldlabel = uilabel(app.leftpanel);
app.tripinmileseditfieldlabel.horizontalalignment = 'right';
app.tripinmileseditfieldlabel.fontcolor = [0 0.4471 0.7412];
app.tripinmileseditfieldlabel.position = [268 176 69 22];
app.tripinmileseditfieldlabel.text = 'trip in miles';
% create tripinmileseditfield
app.tripinmileseditfield = uieditfield(app.leftpanel, 'numeric');
app.tripinmileseditfield.valuechangedfcn = createcallbackfcn(app, @tripinmileseditfieldvaluechanged, true);
app.tripinmileseditfield.fontcolor = [0 0.4471 0.7412];
app.tripinmileseditfield.position = [352 176 100 22];
% create fueltypebuttongroup
app.fueltypebuttongroup = uibuttongroup(app.leftpanel);
app.fueltypebuttongroup.selectionchangedfcn = createcallbackfcn(app, @fueltypebuttongroupselectionchanged, true);
app.fueltypebuttongroup.title = 'fuel type';
app.fueltypebuttongroup.backgroundcolor = [1 0 0];
app.fueltypebuttongroup.position = [40 405 123 76];
% create gasolinebutton
app.gasolinebutton = uiradiobutton(app.fueltypebuttongroup);
app.gasolinebutton.text = 'gasoline';
app.gasolinebutton.position = [11 30 69 22];
app.gasolinebutton.value = true;
% create dieselbutton
app.dieselbutton = uiradiobutton(app.fueltypebuttongroup);
app.dieselbutton.text = 'diesel';
app.dieselbutton.position = [11 8 65 22];
% create trailertowedbuttongroup
app.trailertowedbuttongroup = uibuttongroup(app.leftpanel);
app.trailertowedbuttongroup.selectionchangedfcn = createcallbackfcn(app, @trailertowedbuttongroupselectionchanged, true);
app.trailertowedbuttongroup.title = 'trailer towed';
app.trailertowedbuttongroup.backgroundcolor = [1 1 0];
app.trailertowedbuttongroup.position = [285 405 123 76];
% create yesbutton
app.yesbutton = uiradiobutton(app.trailertowedbuttongroup);
app.yesbutton.text = 'yes';
app.yesbutton.position = [11 30 58 22];
app.yesbutton.value = true;
% create nobutton
app.nobutton = uiradiobutton(app.trailertowedbuttongroup);
app.nobutton.text = 'no';
app.nobutton.position = [11 8 65 22];
% create numberofenginecylindersbuttongroup
app.numberofenginecylindersbuttongroup = uibuttongroup(app.leftpanel);
app.numberofenginecylindersbuttongroup.selectionchangedfcn = createcallbackfcn(app, @numberofenginecylindersbuttongroupselectionchanged, true);
app.numberofenginecylindersbuttongroup.title = 'number of engine cylinders';
app.numberofenginecylindersbuttongroup.backgroundcolor = [0.6353 0.0784 0.1843];
app.numberofenginecylindersbuttongroup.position = [143 248 167 106];
% create button_4
app.button_4 = uiradiobutton(app.numberofenginecylindersbuttongroup);
app.button_4.text = '4';
app.button_4.position = [11 60 58 22];
app.button_4.value = true;
% create button_6
app.button_6 = uiradiobutton(app.numberofenginecylindersbuttongroup);
app.button_6.text = '6';
app.button_6.position = [11 38 65 22];
% create button_8
app.button_8 = uiradiobutton(app.numberofenginecylindersbuttongroup);
app.button_8.text = '8';
app.button_8.position = [11 16 65 22];
% create editfield
app.editfield = uieditfield(app.leftpanel, 'numeric');
app.editfield.position = [186 72 167 22];
% create centerpanel
app.centerpanel = uipanel(app.gridlayout);
app.centerpanel.layout.row = 1;
app.centerpanel.layout.column = 2;
% create calculatebutton
app.calculatebutton = uibutton(app.centerpanel, 'push');
app.calculatebutton.buttonpushedfcn = createcallbackfcn(app, @calculatebuttonpushed, true);
app.calculatebutton.backgroundcolor = [1 0.0745 0.651];
app.calculatebutton.position = [8 383 100 23];
app.calculatebutton.text = 'calculate';
% create plotbutton
app.plotbutton = uibutton(app.centerpanel, 'push');
app.plotbutton.position = [8 136 100 23];
app.plotbutton.text = 'plot';
% create rightpanel
app.rightpanel = uipanel(app.gridlayout);
app.rightpanel.layout.row = 1;
app.rightpanel.layout.column = 3;
% create uiaxes
app.uiaxes = uiaxes(app.rightpanel);
title(app.uiaxes, 'mpg vs. cost per mile')
xlabel(app.uiaxes, 'x')
ylabel(app.uiaxes, 'y')
zlabel(app.uiaxes, 'z')
app.uiaxes.position = [6 54 316 195];
% create milesgalloneditfieldlabel
app.milesgalloneditfieldlabel = uilabel(app.rightpanel);
app.milesgalloneditfieldlabel.backgroundcolor = [0 0 1];
app.milesgalloneditfieldlabel.horizontalalignment = 'right';
app.milesgalloneditfieldlabel.position = [96 468 74 22];
app.milesgalloneditfieldlabel.text = 'miles /gallon';
% create milesgalloneditfield
app.milesgalloneditfield = uieditfield(app.rightpanel, 'numeric');
app.milesgalloneditfield.valuechangedfcn = createcallbackfcn(app, @milesgalloneditfieldvaluechanged, true);
app.milesgalloneditfield.backgroundcolor = [0 0 1];
app.milesgalloneditfield.position = [185 468 100 22];
% create gallonsofusedfueleditfieldlabel
app.gallonsofusedfueleditfieldlabel = uilabel(app.rightpanel);
app.gallonsofusedfueleditfieldlabel.backgroundcolor = [1 0.4118 0.1608];
app.gallonsofusedfueleditfieldlabel.horizontalalignment = 'right';
app.gallonsofusedfueleditfieldlabel.position = [96 413 111 22];
app.gallonsofusedfueleditfieldlabel.text = 'gallons of used fuel';
% create gallonsofusedfueleditfield
app.gallonsofusedfueleditfield = uieditfield(app.rightpanel, 'numeric');
app.gallonsofusedfueleditfield.valuechangedfcn = createcallbackfcn(app, @gallonsofusedfueleditfieldvaluechanged, true);
app.gallonsofusedfueleditfield.backgroundcolor = [1 0.4118 0.1608];
app.gallonsofusedfueleditfield.position = [222 413 100 22];
% create costtofuelupeditfieldlabel
app.costtofuelupeditfieldlabel = uilabel(app.rightpanel);
app.costtofuelupeditfieldlabel.backgroundcolor = [0 1 0];
app.costtofuelupeditfieldlabel.horizontalalignment = 'right';
app.costtofuelupeditfieldlabel.position = [96 362 82 22];
app.costtofuelupeditfieldlabel.text = 'cost to fuel up';
% create costtofuelupeditfield
app.costtofuelupeditfield = uieditfield(app.rightpanel, 'numeric');
app.costtofuelupeditfield.valuechangedfcn = createcallbackfcn(app, @costtofuelupeditfieldvaluechanged, true);
app.costtofuelupeditfield.backgroundcolor = [0 1 0];
app.costtofuelupeditfield.position = [193 362 100 22];
% create costmileeditfieldlabel
app.costmileeditfieldlabel = uilabel(app.rightpanel);
app.costmileeditfieldlabel.backgroundcolor = [0.4941 0.1843 0.5569];
app.costmileeditfieldlabel.horizontalalignment = 'right';
app.costmileeditfieldlabel.position = [96 307 52 22];
app.costmileeditfieldlabel.text = 'cost/mile';
% create costmileeditfield
app.costmileeditfield = uieditfield(app.rightpanel, 'numeric');
app.costmileeditfield.valuechangedfcn = createcallbackfcn(app, @costmileeditfieldvaluechanged, true);
app.costmileeditfield.backgroundcolor = [0.4941 0.1843 0.5569];
app.costmileeditfield.position = [163 307 100 22];
% show the figure after all components are created
app.uifigure.visible = 'on';
end
end
% app creation and deletion
methods (access = public)
% construct app
function app = jonpagelsprojectgui
% create uifigure and components
createcomponents(app)
% register the app with app designer
registerapp(app, app.uifigure)
if nargout == 0
clear app
end
end
% code that executes before app deletion
function delete(app)
% delete uifigure when app is deleted
delete(app.uifigure)
end
end
end
jon
https://ww2.mathworks.cn/matlabcentral/profile/authors/30077047
tag:ww2.mathworks.cn,2005:question/1979804
2023-06-07t16:26:35z
2023-06-07t22:19:53z
create a stand-alone legend for tabulated data
i'm analyizing old datasets for work. as part of this work i am grouping the data into bins as shown in the table. i am then creating pdf reports of the data, and as part of that pdf creation i need a stand alone legend to insert into its own area. historically i had done a continuous color scale, and was easily able to produce a stand alone colorbar, but the powers who be would like discrete data groupings.
i am struggling with producing figure handles in a loop that then can be used to produce a stand alone legend. all attempts are failing. the general code is this (i've stripped all my attempts out of the the legend producer):
dat_bins=readtable("bin_input.xlsx");
%create rgb's for dat_bins
for j=1:length(dat_bins.bin_color)
if matches(string(dat_bins.bin_color(j)),"b")
dat_bins.rgb{j}=[0 0 1];
elseif matches(string(dat_bins.bin_color(j)),"g")
dat_bins.rgb{j}=[0 1 0];
elseif matches(string(dat_bins.bin_color(j)),"y")
dat_bins.rgb{j}=[1 1 0];
elseif matches(string(dat_bins.bin_color(j)),"o")
dat_bins.rgb{j}=[1 165/255 0];
else
dat_bins.rgb{j}=[1 0 0];
end
end
fig_leg=figure('visible', 'on'); %create stand alone legend
axis off
for k=1:length(dat_bins.bin_start)
fig_leg(k) = plot(nan, nan, 'color', dat_bins.rgb{k});
end
legend(fig_leg, {string(dat_bins.bin_name)'})
any help would be greatly appreciated.
oran
https://ww2.mathworks.cn/matlabcentral/profile/authors/9400431
tag:ww2.mathworks.cn,2005:question/1913725
2023-02-16t14:06:17z
2023-06-07t22:19:31z
ind2sub with arbitrary martix
hi
i intend to use ind2sub to get the subscripts indexing from linear indexing and i will use if to read data in matrix of arbitrary size.
the problem with this is that you have to know the dimension of the matrix, so that you can call ind2sub with the corresponding number of outputs. what i would like is to get a output vector that has the corresponding number of elements. is this possible to achieve?
best regards
thomas
thomas
https://ww2.mathworks.cn/matlabcentral/profile/authors/28581720
tag:ww2.mathworks.cn,2005:question/1979889
2023-06-07t21:47:28z
2023-06-07t22:05:39z
find probability of some data
i have some data in simulink, i want to know what is the probability of these data to be less than some determined constant number?
is there any function or way in matlab to find it?
imp nig
https://ww2.mathworks.cn/matlabcentral/profile/authors/13856413
tag:ww2.mathworks.cn,2005:question/1978684
2023-06-05t16:25:49z
2023-06-07t21:53:08z
unit delay block is supposed to be not a direct feedthrough but in documentation it is said yes
in algebraic loop descrption here it is mentioned that:
"examples of blocks that do not have direct feedthrough include the integrator block and the unit delay block."
but
if we see in the"help" of unit delay block it says yes it is a direct feedthrough block. (see the snapshot of unit delay help)
fahad
https://ww2.mathworks.cn/matlabcentral/profile/authors/10671344
tag:ww2.mathworks.cn,2005:question/1979144
2023-06-06t14:27:06z
2023-06-07t21:47:33z
how to fft a noisy earthquake data
if someone could help me, i need to fft an actual earthquake data retrieved from the sensor installed in our school. i saw some articles that i first need to remove mean value, apply baseline correction, and filter before doing so. thank you very much.
mary claire
https://ww2.mathworks.cn/matlabcentral/profile/authors/30016698
tag:ww2.mathworks.cn,2005:question/66780
2013-03-11t22:32:27z
2023-06-07t21:43:41z
multiply each element of structured array, assignment of structured array
i'm not exactly sure if i'm using the right terminology. i have
a(1).b = 5;
a(2).b = 6;
a(3).b = 7;
>>a.b
ans =
5
ans =
6
ans =
7
i have two questions:
1. i want to multiply each element of the structured array so that
a.b*2 would equal 10,12,14 instead of 5,6,7.
but instead i get the error
>>a.b*2
error using *
too many input arguments.
2. how do i make a copy of the structured array? i have tried but it just results in the first element.
>>c = a.b
c =
5
likewise
>> c = a(1:3).b
c =
5
instead of c(1).b = 5, c(2).b = 6, and c(3).b = 7 like i want.
john petersen
https://ww2.mathworks.cn/matlabcentral/profile/authors/2436045