https://la.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2019-03-22T08:27:42Ztag:la.mathworks.com,2005:Question/4516602019-03-22T08:17:52Z2019-03-22T08:27:42Zxlmtree undefined function readI copied the xlmtree folder into the toolbox folder of matlab.
While I keep the file of the data : AI.xrdml inside a folder of Pc desktop .
Actually, the path of MAtlab is the following '/Users/name/Desktop/Xray/xmltree-2.0/'
Then I run the following script
d = XRDMLread('AU.xrdml') %#ok<NOPTS>
% plot data
figure
semilogy( d.x , round(d.data*d.time) )
box on
xlabel( [d.xlabel '(' d.xunit ')'] )
ylabel( 'Intensity (counts)' )
title( d.filename , 'Interpreter','none','FontName','Helvetica')
And the output is the following:
>> xray
Undefined function or variable 'XRDMLread'.
Error in xray (line 3)
d = XRDMLread('AU.xrdml') %#ok<NOPTS>
Can someone help me to solve this problem?
giuseppina simonehttps://la.mathworks.com/matlabcentral/profile/authors/10171097-giuseppina-simonetag:la.mathworks.com,2005:Question/4514152019-03-21T13:04:22Z2019-03-22T08:24:14Zhow to get back numerical value from stringV = [-0.00153846153846154; 0; -0.000769230769230769; -0.0126923076923077; 0.00384615384615385];
M = dec2bin(typecast(double(V),'uint8'));
Mbin = reshape(dec2bin(double(M),8).',[],1);
Mbint = Mbin';
fid = fopen('temp.txt','w');
fprintf(fid, '%s', Mbint);
fclose(fid);
fid = fopen('temp.txt','r');
F = fread(fid);
how can i get vector V back from F Elysi Cochinhttps://la.mathworks.com/matlabcentral/profile/authors/3625227-elysi-cochintag:la.mathworks.com,2005:Question/4516222019-03-22T02:24:00Z2019-03-22T08:23:38ZPDEPE boundary condition outputting odd results.For the boundary condition I've set the left (pl) to a constant value of 280 with the idea being that this value will always be 280, however when i output the results the value is instead 4e10 and appears to be changing. What am I doing incorrectly so that my boundary condition is a) not constant and b) way above the value I've stated.
I've gone over the pdepe page a few times trying to figure it out but unfortauntely haven't made much progress.
Thank you for any help provided.
m = 0;
tspan = linspace(0,365*20*86400,21);
xmesh = linspace(0,20,201);
sol = pdepe(m,@pdefun,@icfun,@bcfun,xmesh,tspan);
u = sol(:,:,1);
figure, plot(u(2,:),xmesh)
ylabel('Depth (m)')
xlabel('Oxygen Concentration (g/m3)');
set(gca, 'XAxisLocation', 'top')
set(gca, 'YDir','reverse')
function[c,f,s]=pdefun(x,t,u,DuDx)
c = 0.18;
f = 1e-8*DuDx;
s = -1e-9*u;
end
function u=icfun(x)
u = 0;
end
function[pl,ql,pr,qr]=bcfun(xl,ul,xr,ur,t)
pl = 280;
ql = 1;
pr = ur;
qr = 0;
end Scott Lineshttps://la.mathworks.com/matlabcentral/profile/authors/8829112-scott-linestag:la.mathworks.com,2005:Question/4514162019-03-21T13:11:30Z2019-03-22T08:20:00ZPlot a drawn, filled shape at each data pointI have a matrix which contains X & Y data for seperate, single point locations to be plotted on a map using a marker for each point (kind of like multiple 'X marks the spot' on a map)
This works well until I scale the figure window & then the markers become a lot smaller than the data they represent.
How would I plot a filled unit square centred on each data point e.g. if the first point to be plotted is at (50, 10) I would like to draw a square (49.5, 9.5) (50.5, 9.5) (50.5, 10.5) (49.5, 10.5) & fil the square in a particular colour?DrEamonnhttps://la.mathworks.com/matlabcentral/profile/authors/14791607-dreamonntag:la.mathworks.com,2005:Question/4516592019-03-22T08:10:51Z2019-03-22T08:17:10ZReading all the .wav files from a particular folderI am working on a project, where i am determining the Emotion of a Person based on his speech. Now I am having a folder with 100 voices. I am able to process for 1 .wav file, but I need to do that for all the .wav files present in that folder. How can I read all these .wav files, from that folder at once.aditya chiruvoluhttps://la.mathworks.com/matlabcentral/profile/authors/10630884-aditya-chiruvolutag:la.mathworks.com,2005:Question/4516332019-03-22T05:03:09Z2019-03-22T08:15:42ZAttempting to automate the importing of text file dataI am trying to automate the importing of text file data. How can I call each individual text file name, which is variable, in the readtable function? I have a variable with each textfile name, but am having difficulty using that in the readtable function. Is that a good way to do it? Im not even sure. I attached two text files for examples, any help is appreciated.
textfiles = dir('*.txt');
numboffiles = length(textfiles);
filelist = {ones(1:numboffiles)};
for j =1:numboffiles
filelist(j) = {textfiles(j).name};
end
data = ones(length(filelist));
for i = 1:length(filelist)
fid = fopen(filelist{i});
if fid == -1
fprintf ('Wrong File Name');
else
data(i) = readtable(filelist(j), 'Delimiter', '\t', 'ReadVariableNames',false, 'HeaderLines', 9);
end
end
Jacob Lobaohttps://la.mathworks.com/matlabcentral/profile/authors/14913014-jacob-lobaotag:la.mathworks.com,2005:Question/4516512019-03-22T06:54:54Z2019-03-22T08:13:47ZHow to put hat over a greek symbol express its value in legend of a plot?I want to write expressions like alpha_0 cap(or hat)=0, alpha_0 cap(or hat)=1 and so on in legend of a plot.
Need to display aplha, with subsscript zero, with a hat, equate to a numerical value.
Kindly help me.YADU NARENDRANhttps://la.mathworks.com/matlabcentral/profile/authors/11777533-yadu-narendrantag:la.mathworks.com,2005:Question/235632011-12-10T08:18:08Z2019-03-22T08:13:24Zmppt by using pso method hello evry 1. im doing a simulation based on pso method to get a output from mppt which source by a solar. i am also in in beginer stage so im looking foward from anybody that coulod help me to solve my proble here..is there anybody who had done this type of project before so can help futher to succes my project..
hope a reply soon.
tqismahttps://la.mathworks.com/matlabcentral/profile/authors/3190695-ismatag:la.mathworks.com,2005:Question/4516502019-03-22T06:48:58Z2019-03-22T08:13:21ZI have five data points (A, B, C, D, E) in a two dimensional plane. Based on the euclidean distance between these points how can I group them?I have five data points (A, B, C, D, E) in a two dimensional plane where three points (A, B, D) are close to each other and remaining two (C, E) are far from the group. If I calculate the distances between these points the results are
dist(A, B) = 0.3, dist(A, C) = 1.3, dist(A, D) = 0.15, dist(A, E) = 1.0, dist(B, C) = 0.9, dist(B, D) =0.2, dist(B, E) = 1.1, dist(C, D)=1.6, dist(C, E) = 1.0, dist(D, E) = 1.5.
Now if I choose a distance threshold as 0.6, I need to get a result as:
A, B, D (Closer to each other)
C (far from other points)
E (far from other points)
Shaik Ahmadhttps://la.mathworks.com/matlabcentral/profile/authors/6789025-shaik-ahmadtag:la.mathworks.com,2005:Question/4513802019-03-21T10:20:51Z2019-03-22T08:12:51ZMultidimensional matrix to use for loopI have a multidimensional matrix which is X.
when i type X in command window the answer is below.
X(:,:,1)
10 5 2
5 3 1
X(:,:,2)
8 4 1
7 -5 -10
X(:,:,3)
18 15 7
12 11 9
ı want to write a code using for loop to calculate some values form this matrix.
i mean
for i=1:3
a(i)=X(i)
end
something like this.
I want to get matrices as
a(1)=X(:,:,1)
a(2)=X(:,:,2)
a(3)=X(:,:,3)
How can i get it?Gko Khttps://la.mathworks.com/matlabcentral/profile/authors/14914680-gko-ktag:la.mathworks.com,2005:Question/4516572019-03-22T08:04:05Z2019-03-22T08:12:11ZSystem of equations with for loop (3 variables and 10 equations)Hello all :)
I am trying to solve a system of equations with for loop (3 variables and 3 equations, 10 times):
TSR=7.5; %Tip Speed Ratio
k=2;
eps_design=0.0023;
x=linspace(1,TSR,10)';
%a, a', beta_i
syms a a_prime_for beta_i_for
a = zeros(size(x));
a_prime = zeros(size(x));
beta_i = zeros(size(x));
for i = 1:numel(x)
eqn_1 = a_for/(1-a_for)==(F*cos(beta_i_for)*(1+eps_design*tan(beta_i_for)))/(8*pi*k*(sin(beta_i_for))^2);
eqn_2 = a_prime_for/(1+a_prime_for)==(F*(1-eps_design*cot(beta_i_for)))/(8*pi*k*cos(beta_i_for));
eqn_3 = tan(beta_i_for)==(1-a_for)/(x(i)*(1+a_prime_for));
eqns=[eqn_1,eqn_2,eqn_3];
S=double(vpasolve(eqns,[a_for a_prime_for beta_i_for]));
[a(i),a_prime(i),beta_i(i)]=[S.a_for,S.a_prime_for,S.beta_i_for];
end
But I get this error, and I don't understand it:
This expression cannot be assigned to multiple values. (line [a(i),a_prime(i),beta_i(i)]=[S.a_for,S.a_prime_for,S.beta_i_for];)
Error using sym.getEqnsVars>checkVariables (line 92)
Second argument must be a vector of symbolic variables.
Error in sym.getEqnsVars (line 54)
checkVariables(vars);
Error in sym/vpasolve (line 132)
[eqns,vars] = sym.getEqnsVars(varargin{1:N});
Error in Assigment1 (line 207)
S=double(vpasolve(eqns,[a_for a_prime_for beta_i_for]));
Thank you in advance for your help :)Bertrand Canettihttps://la.mathworks.com/matlabcentral/profile/authors/15071882-bertrand-canettitag:la.mathworks.com,2005:Question/4516542019-03-22T07:53:37Z2019-03-22T08:09:42ZProduct of two normal distribution. Z = XY; where X is normal distribution N1(mu1,std1) and y is also normal distribution N2(mu2,std2).If we multiply directly, then the new mean is mu = (mu1 * std2^2 + mu2 * std1^2)/(std1^2 + std2^2) and std^2 is (std1^2 + std2^2).
suppose we have on simple formula distance = speed * time, where mean of speed is 5 and mean of time is 3. Then mean of the distance would be 15.
If we transfer this formula in distribution, with some stnadard deviation.
But frequently, take std1 = 1 and std2 = 1. Then apply mean and standard deviation in the main above formula . The calculated mean and std^2 is 7.5 and 0.5. The calculatede mean is far away from the distance value. Deepak Kumarhttps://la.mathworks.com/matlabcentral/profile/authors/11101820-deepak-kumartag:la.mathworks.com,2005:Question/4514762019-03-21T15:18:20Z2019-03-22T08:08:30ZMatlab Serial using wrong frequency?Hello there.
So im using matlab for reading an Arduino, which I have programmed for sending data at 50Hz (1 sample per 0.02 sec).
And the problem Im facing is that matlab is reading those samples too slow.
I made a simple script to check the time it takes to read one sample:
s = serial(seriallist,'BaudRate',9600,'Terminator','CR');
fopen(s);
% s.ReadAsyncMode = 'manual';
% readasync(s)
tic
linea = fscanf(s);
toc
It takes 1,98 seconds for reading and I dont really understand why.
I really want it to go at 50Hz since what Im attempting to do is to plot the data on real time using a while (1) loop, and the latency right now is too high for the application to run smoothly.
Thanks in advance.Guillermo Lacallehttps://la.mathworks.com/matlabcentral/profile/authors/7774815-guillermo-lacalletag:la.mathworks.com,2005:Question/4516322019-03-22T04:57:46Z2019-03-22T08:08:30ZError: Cannot convert double value 5 to a handlePlease help me fix the following code and avoid getting "Cannot convert double value 5 to a handle" error.
set(h,'userdata',[sch(ii,1) ii h])
while h is a 1×9 graphics array:
Line Line Line Line Line Line Line Text TextS Hhttps://la.mathworks.com/matlabcentral/profile/authors/6229522-s-htag:la.mathworks.com,2005:Question/4516582019-03-22T08:08:07Z2019-03-22T08:08:07Z, i need to denoise the signalIam beginner to matlab, i need to denoise the signal available in .easy format using DWT technique ,whether i need to specify the same rate for this?Rajendran V Ghttps://la.mathworks.com/matlabcentral/profile/authors/14824144-rajendran-v-gtag:la.mathworks.com,2005:Question/1219852014-03-18T00:30:07Z2019-03-22T08:05:39Zsolar mppt by pso at simulink hello every one. i am doing a simulation based on pso mppt to find pmax which source by a solar. i am also in beginner stage so i need your help to indicate how can i write code ? and how add it at simulink ? please any one help me
thanks in advance dalia elkashefhttps://la.mathworks.com/matlabcentral/profile/authors/2586072-dalia-elkasheftag:la.mathworks.com,2005:Question/4516562019-03-22T08:04:02Z2019-03-22T08:04:02ZTCPIP connection won't open in compiled projectI have the following file PICOLOGGER.m
Which connects to local host and sends and receives a message. This works fine when run from the matlab environment, however I cannot compile the script to a standalone exe and get it to work.
t = tcpip('127.0.0.1', 1024)
fopen(t)
t.Status
fprintf(t, 'CMODE;R;')
data=fscanf(t);
fprintf(t, 'ARCRV?')
data=fscanf(t)
results(1)=string(datetime('now'));
results(2)=string(data(2:7));
results(3)=string(data(10:15));
fclose(t);
delete(t);
clear t
echotcpip('off');
When compiled to standalone exe I get this eorror output in the command window:
Here is the successful running that I see when I run the original uncompiled version in the matlab environment:
What gives! Had quite a lot of issues trying to get things working in the matlab compiler.
Thanks!!!
Steve
Steven Bracehttps://la.mathworks.com/matlabcentral/profile/authors/15069867-steven-bracetag:la.mathworks.com,2005:Question/4514322019-03-21T14:06:27Z2019-03-22T08:02:00Zusing for loop to increase the number of variablefor i= 1: 16
velocities_boids_i= cell(13,3);
velocities_boids_i = zeros(13,3)
velocities_boids(:,1,1)={'Sim Time (s)','Position_x%d', 'Position_y%d' , i, i};
end
------------------------------------
I want to make the following result.
Now this code get the errors.
How can I use for-loop in a varialble's name?
Thanks in advance.
-----------------------------------------------.
velocities_boids_1=
Sim Time (s) Position_x1 Position_y1
0 0 0
0 0 0
.
.
.
velocities_boids_2=
Sim Time (s) Position_x2 Position_y2
0 0 0
0 0 0
.
.
.
-------------------------------------------------------------------------------------------
Daewoonhttps://la.mathworks.com/matlabcentral/profile/authors/15099363-daewoontag:la.mathworks.com,2005:Question/4516532019-03-22T07:49:03Z2019-03-22T07:59:45Zadd zero elemant inside cellA={[95],[112],[98],[84],[69],[121],[108]};
B={[1,2,4],[4,3],[6,9,98],[3,7,88],[2,9,1],[55,7],[1,4],[0],[0]};
if size(A,2)<size(B,2)
% add zero at the end of A
end
I want that size of A and B should be the same
result should be
A={[95],[112],[98],[84],[69],[121],[108],[0],[0]};Naimehttps://la.mathworks.com/matlabcentral/profile/authors/13711668-naimetag:la.mathworks.com,2005:Question/4516202019-03-22T02:17:55Z2019-03-22T07:56:30ZDefine a 100 * 100 symbolic matrix whose elements are the function of a symbolic variable tHi guys,
I want to define a symbolic matrix whose size is 100 * 100. All of the elements inside the matrix are all functions of time t. Also, I want to make the variable t a symbolic variable.
So how to define this matrix and write the codes in Matlab ?
Thanks so much!
Cheers
Tony Chenghttps://la.mathworks.com/matlabcentral/profile/authors/9474183-tony-chengtag:la.mathworks.com,2005:Question/4515652019-03-21T19:43:42Z2019-03-22T07:56:25ZSolving for a variable with varying parameters in the sum being the unknown variable, how to initialize and write the following equation in matlab script containing varying paramters.
(n = 0,1,2,...)
Jigsawhttps://la.mathworks.com/matlabcentral/profile/authors/13114140-jigsawtag:la.mathworks.com,2005:Question/4516552019-03-22T07:54:06Z2019-03-22T07:54:06ZDenoising sound sample using noise segmentsHello,
I have these sound samples of mice recording,
Now there mice, they communicate in ultrasonic voalizations, each vocalization is refered to as a "Call" which is comprized of short syllables (~100 milisec)
I have a collection there Call recordings, along with a table for each call indicating the onset and offset of each syllable, mean that i can separtare the sound vectros into bits that has the important sound and bits that have the backgroud.
I am looking for an algorithem with which I can subtract the the background from the syllable and get a clean sample.
I have seen this done in Audasity, and it wors like a charm, but i have hunderds of call samples containing thousends of syllables, and i cant do them all manually.
I tried to convert both segments (signal+noise and noise) with fft and then binning the the elements to create 125 scale (representing the frequency) and then subtracing one from the other but then i get negative values in the lower frequencies.
Is there an algorithem to use? or is it just subtracting noise from signal+noise?ytzhak gousshahttps://la.mathworks.com/matlabcentral/profile/authors/11482545-ytzhak-gousshatag:la.mathworks.com,2005:Question/4516122019-03-21T23:55:19Z2019-03-22T07:43:29ZHow to solve the "Not enough input arguments" in bvp4c ?Good evening,
I am trying to model the trajectory of a rocket launch for its first stage, from lift-off (0 seconds) to first burn-out (118 seconds), as a boundary value problem using bvp4c. I am using 8 state variables, being y(1)=x, y(2)=x', y(3)=z, y(4)=z', y(5)=v, y(6)=v', y(7)=γ, y(8)=γ'. They make up a system of 8 first order ODEs, so I am using 8 boundary conditions and 8 initial guessed value. When I run the simulation an error comes up, saying "Not enough imput arguments". I have triple checked the code to ensure all variables used appear in the arguments, but it still doesn't solve it.
Here is the code, I am using 4 files .m in total.
ValuesVariables.m (here is where I stored all the variables used):
t=linspace(0,118,119);
FBSL=839100;
FBVac=1020400;
FCSL=792400;
FCVac=985600;
MatB=[(log(0+1)+1) 1 FBSL; (log(180000+1)+1) 1 FBVac];
BatB=rref(MatB); BatB13=BatB(1,3); BatB23=BatB(2,3);
MatC=[(log(0+1)+1) 1 FCSL; (log(180000+1)+1) 1 FCVac];
BatC=rref(MatC); BatC13=BatC(1,3); BatC23=BatC(2,3);
CD= 0.2;
rho_0E=1.225;
rho_41E=0.002927;
ED1=4.7;
MatD1 = [1 1 rho_0E; exp(-ED1) 1 rho_41E];
BatD1=rref(MatD1); BatD113=BatD1(1,3); BatD123=BatD1(2,3);
dB=2.68;
dC=2.95;
A1=4*pi*(dB/2)^2+pi*(dC/2)^2;
muE=3.98199;
REarth=6371000;
MfB=39600;
MfB=39600;
MfB=39600;
MfFregat=5350*0;
Mp=6560;
MS=25200;
MsB=3810;
MsC=6550;
Ms3=2410;
MsFregat=1000*0;
tBO1=118;
tBO2=280;
MT1E=-4.*((MfB/tBO1).*t)-((MfC/tBO2).*t)+(4.*MfB+MfC+Mf3+MfFregat+4.*MsB+MsC+Ms3+MsFregat+Mp);
bvpTEST.m (here is the bvp4c command is):
clear;
ValuesVariables;
init=bvpinit(linspace(0,118,50),@init_0_118);
sol=bvp4c(@rhs_0_118,@bc_0_118,init);
t=linspace(0,118,119);
BS=deval(sol,t);
plot(t,BS);
rhs_0_118.m (here I defined the ODEs):
function rhs=rhs_0_118(t,y,BatB13,BatB23,BatC13,BatC23,BatD113,BatD123,ED1,CD,A1,muE,REarth,MfB,tBO1,MfC,tBO2,MT1E)
rhs=zeros(8,1);
rhs(1)=y(5).*cos(y(7));
rhs(2)=((2.*y(6).*((((y(2)).^2)+((y(4)).^2)).^(0.5)))-(2.*y(4).*y(6).*sin(y(7)))).*((2.*y(2)).^(-1));
rhs(3)=y(5).*sin(y(7));
rhs(4)=((2.*y(6).*((((y(2)).^2)+((y(4)).^2)).^(0.5)))-(2.*y(2).*y(6).*cos(y(7)))).*((2.*y(4)).^(-1));
rhs(5)=(((((BatB13.*(log(y(3)+1)+1)+BatB23))+((BatC13.*(log(y(3)+1)+1)+BatC23)))-((0.5).*CD.*A1.*((y(5)).^2).*(BatD113.*exp(-ED1.*(y(3)).*(1/41000))+BatD123))).*((MT1E).^(-1)))-((muE.*((REarth+y(3)).^(-2))).*cos(y(7)));
rhs(6)=-(((BatB13.*(log(y(3)+1)+1)+BatB23))+((BatC13.*(log(y(3)+1)+1)+BatC23))).*((MT1E).^(-2)).*(-4.*(MfB/tBO1)-(MfC/tBO2))-(0.5).*(BatD113.*exp(-ED1.*(y(3)).*(1/41000))+BatD123).*(CD).*(A1).*(2.*(y(5).*(y(6)).*((MT1E).^(-1)))-((y(5)).^(2)).*((MT1E).^(-2)).*(-4.*(MfB/tBO1)-(MfC/tBO2)))+muE.*((REarth+y(3)).^(-2)).*y(8).*sin(y(7));
rhs(7)=-(muE.*((REarth+y(3)).^(-2))).*(cos(y(7)).*((y(5)).^(-1)));
rhs(8)=(muE.*((REarth+y(3)).^(-2))).*(((y(5)).^(-1)).*y(8).*sin(y(7))+((y(5)).^(-2)).*y(6));
end
bc_0_118.m (here I defined all the boundary conditions):
function bc=bc_0_118(yl,yr)
bc=zeros(8,1);
bc(1)=yl(1);
bc(2)=yl(3);
bc(3)=yl(5);
bc(4)=yl(7)-(pi/2);
bc(5)=yr(1)-39000;
bc(6)=yr(3)-41000;
bc(7)=yr(5)-(8300.*1000.*((60*60).^(-1)));
bc(8)=yr(7)-(pi/3);
end
init_0_118.m (here I defined the initial guessed values):
function in=init_0_118(t)
in=zeros(8,1);
in(1)=1;
in(2)=1;
in(3)=1;
in(4)=9.81;
in(5)=1;
in(6)=9.81;
in(7)=(pi/2);
in(8)=0;
end
That is the whole code, and here is the error:
Not enough input arguments.
Error in rhs_0_118 (line 9)
rhs(5)=(((((BatB13.*(log(y(3)+1)+1)+BatB23))+((BatC13.*(log(y(3)+1)+1)+BatC23)))-((0.5).*CD.*A1.*((y(5)).^2).*(BatD113.*exp(-ED1.*(y(3)).*(1/41000))+BatD123))).*((MT1E).^(-1)))-((muE.*((REarth+y(3)).^(-2))).*cos(y(7)));
Error in bvparguments (line 105)
testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 130)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in bvpTEST (line 5)
sol=bvp4c(@rhs_0_118,@bc_0_118,init);
I tried including all variable names in the all function files, or only writing the ones that appear in the files assuming that each variable is accounted for since I call the "ValuesVariables" anyway, but it doesn't work. I suspect I didn't write the variable "t" where I should have, and that the problem has to do with the "init_0_118.m" file, but I can't spot it.
Any help with this would be highly appreciated, thank you in advance.
DaveDave Bhttps://la.mathworks.com/matlabcentral/profile/authors/13668855-dave-btag:la.mathworks.com,2005:Question/4516522019-03-22T07:41:50Z2019-03-22T07:41:50ZFor Iterator Block Not present in Library , Any Idea ?There is For Iterator Subsystem block as per the given link
https://in.mathworks.com/help/simulink/slref/foriteratorsubsystem.html
and There is a For Iterator block as per the below link present in the "Ports and Subsystems" Library block
https://in.mathworks.com/help/simulink/slref/foriterator.html
I could find the For Iterator Subsystem block but not able to find the For iterator block in the "Ports and Subsystems" Library block
nor after a search in the complete Simulink Library , is the only place where "For iterator block" can be found is inside "For Iterator Subsystem"
or there is something wrong with the Matlab installation.
This is the screen shot of the blocks present in my installation of "Ports and Subsystems" Library block
ANKUR WADHWAhttps://la.mathworks.com/matlabcentral/profile/authors/7758313-ankur-wadhwatag:la.mathworks.com,2005:Question/4512502019-03-20T19:08:26Z2019-03-22T07:34:38Z---- ------- ---- -----------------Erika Plekaviciutehttps://la.mathworks.com/matlabcentral/profile/authors/14595194-erika-plekaviciutetag:la.mathworks.com,2005:Question/4513312019-03-21T04:50:56Z2019-03-22T07:33:10ZHow to take the fourth derivative of a reflectance graphHi I am looking to calculate and plot the fourth derivtative of a reflectance plot for coral spectra - commonly done in papers by the savistky and golay, 1964 method.
I have used the smoothing function on my coral mean spectra (x3) (1st image)
S2 = smooth(S1);
plot(wv1, S2);
xlim([400 750])
Then went to take my 1st derivative (2nd image)
This turned out ok using this coding:
dy = diff(S2)/diff(wv1);
plot(wv1(2:end),dy)
xlim([400 750])
But I believe this is the wrong method for taking the derivative of the reflectance spectra as I loose data going fromm 1446x1 to 1445x1 each time i derive i.e.
taking the second derivative like so:
d2ydx2 = diff(dy)./diff(wv1);
plot(wv1(1:1444),d2ydx2)
xlim([400 750])
producing a graph like image 3 - which when it comes to the 4th i have lost nearly all the data (image 4)
Does anyone know where I am going wrong, as this must be much more straight forward given it has been used so frequently.
ThanksErin Brownehttps://la.mathworks.com/matlabcentral/profile/authors/11397100-erin-brownetag:la.mathworks.com,2005:Question/3933182018-04-07T15:03:51Z2019-03-22T07:32:06Zgriddata not creating a smooth interpolationI'm trying to create a surface using the following data
<</matlabcentral/answers/uploaded_files/112045/n_map%20emrax.jpg>>
I've collected some rough data points, plotted in this figure (contours added for clarity)
<</matlabcentral/answers/uploaded_files/112047/motor%20n%20map%20contour.jpg>>
However when I use griddata to interpolate and then mesh the values, the result isn't the 'hill shape' you'd expect, instead it is very uneven as seen below (data points in black)
<</matlabcentral/answers/uploaded_files/112048/motor%20interpol%20bad.jpg>>
the central section seems very smooth however both sides are a mess. I've tried the curve fitting app within matlab but the result is the same. Below is the code and data used:
Tmod=[50 100 150 175 200 240 245 245 245 245 245 245 245 245 230 200 150 125 110 100 60 50 35 25 20 20 20 20 25 30 50 100 150 200 230 230 230 230 230 230 230 230 200 150 125 100 75 55 50 45 45 45 45 45 70 100 150 185 200 200 200 200 200 200 200 150 100 70 60 55 55 55 55 100 150 165 170 170 165 160 155 150 100 80 75 70 65 90 110 125 130 125 125 115 100 80 75 75 100 ];
wmod=[250 250 400 500 515 1000 1500 2000 2500 3000 3500 4000 4500 5000 5000 5000 5000 5000 5000 4900 4500 4300 4000 3500 3000 2500 2000 1500 1000 500 1000 600 750 1000 1500 2000 2500 3000 3500 4000 4500 4990 4990 4990 4990 4750 4500 4000 3800 3500 3000 2500 2000 1500 1000 950 1000 1500 2000 2500 3000 3500 4000 4500 4980 4980 4500 4000 3500 3000 2500 2000 1500 1400 1200 1500 2000 2500 3000 3500 4000 4100 4000 3500 3000 2500 2000 1500 1500 1500 2000 2500 3000 3500 3500 3000 2500 2000 1600];
nmod=[86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 86 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 94 94 94 94 94 94 94 94 94 94 94 94 94 94 94 94 94 94 94 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 96 96 96 96 96 96 96 96 96 96 96];
[wq,Tq]=meshgrid(0:45:4500, 0:2.5:250);
nmap=griddata(wmod,Tmod,nmod,wq,Tq);
figure
mesh(wq,Tq,nmap)
Please let me know if anything is unclear - thanks in advance!Alex Raimeshttps://la.mathworks.com/matlabcentral/profile/authors/7632324-alex-raimestag:la.mathworks.com,2005:Question/4505332019-03-17T12:47:50Z2019-03-22T07:29:27Zhow can i make a plot such that the tangent to the circular arc is an axis and the normal is another axis ???? how can i make a plot such that the tangent to the circular arc is an axis and the normal is another axis ???? surendra bhattahttps://la.mathworks.com/matlabcentral/profile/authors/12849508-surendra-bhattatag:la.mathworks.com,2005:Question/3421992017-05-27T19:42:06Z2019-03-22T07:18:52ZI can not get the exact result for CORDIC algorthims clear all
close all
clc
K=1;
for i=1:100;
K=K*sqrt(1+2^(2*(1-i)));
end
x(1) = 1/K;
y(1) = 0;
z(1) = 0.375;
for i=1:15;
theta(i) = atan(1./2^(i));
if(z(i)>=0)
x(i+1)=x(i) - (2^-i)*y(i);
y(i+1)=y(i) + (2^-i)*x(i);
z(i+1)=z(i) - theta(i);
else
x(i+1)=x(i)+(2^-i)*y(i);
y(i+1)=y(i)-(2^-i)*x(i);
z(i+1)=z(i)+theta(i);
end
% x(i)=x(i+1);
% y(i)=y(i+1);
% z(i)=z(i+1);
if(abs(z(i+1))<0.001)
break;
end
end
x(i+1)
y(i+1)
disp('Exact Answer is')
cos(30)
sin(30)
ahmed Alkhayyathttps://la.mathworks.com/matlabcentral/profile/authors/9411150-ahmed-alkhayyattag:la.mathworks.com,2005:Question/3372772017-04-25T20:45:45Z2019-03-22T07:14:07ZTurning a modified image into a matrixHi,
I have made changes to an image but it comes across as not what i want.
To solve this i took the original image and said x = imshow(image, [0 255]);
how can i turn 'x' into a matrix of values, such that when i type y=imshow(x) it returns the modified image.Optical_Stresshttps://la.mathworks.com/matlabcentral/profile/authors/10076081-optical_stresstag:la.mathworks.com,2005:Question/4516462019-03-22T06:24:35Z2019-03-22T06:53:18ZArray indices must be positive integers or logical values (image processing)x = imread('cameraman.jpg');
[M,N]=size(x)
for i=1:M
for j=1:N
I=x(i,j);
x(i,j)=xL(I)+( L(I)*lambda(i,j) );
end
end
where
xL is 1x256 dimension, xL is 1x256 dimension, and lambda is 256x256 dimension which is same with x that has 256x256 dimension.
I get this error:
Array indices must be positive integers or logical values.
Error in edge_enhancing (line 134)
x(i,j)=xL(I)+( L(I)*lambda(i,j) );
PleYohanes Setiawanhttps://la.mathworks.com/matlabcentral/profile/authors/14751841-yohanes-setiawantag:la.mathworks.com,2005:Question/4510602019-03-19T23:36:38Z2019-03-22T06:51:23ZHow can I get and write data from text file?Text file as follows:
A column: Year (1998:1:2017)
B column: Day of the year (1:1:365 or 366)
C column: Hour
1998 152 1 30 25 12.5
1998 152 1 30 30 12
1998 152 1 30 35 11.8
1998 152 1 30 40 11.9
1998 152 1 30 45 12
I would like to get data but I have problem for leap year of 366 days. I'd like to extract all rows and then write data to text file, which is D= 30 and E=25 and B>=152 and B<=243 but it changes B>=153 and B<=244 according to leap years. I tried something but I got 0 and 1. How can I write text file what I want?
load fulltable.txt;
yearlenght = 365+(eomday(fulltable(:,1),2) == 29);
if fulltable(:,1) == yearlenght;
test = fulltable(fulltable(:,2)>=153 & fulltable(:,2)<=244 & fulltable(:,4)==30 & fulltable(:,5)==25,:);
else fulltable(:,1) ~= yearlenght;
test = fulltable(fulltable(:,2)>=152 & fulltable(:,2)<=243 & fulltable(:,4)==30 & fulltable(:,5)==25,:);
endSuat YAZICIhttps://la.mathworks.com/matlabcentral/profile/authors/13285733-suat-yazicitag:la.mathworks.com,2005:Question/4516492019-03-22T06:41:40Z2019-03-22T06:50:17ZHow can I create a 2D plot using a parfor loop?I have some code that works as expected in a for-loop, but I would like to know if I can procude the same results instead using a parfor-loop.
I am new to parfor-loops so please inform me if I am using this featture incorrectly.
This code works as expected and produces an adequate plot:
L1 = 10;
L2 = 5;
L3 = 3;
theta1 = (0:5:90);
theta2 = (0:5:180);
theta3 = (0:5:180);
[THETA1,THETA2] = meshgrid(theta1,theta2);
figure
hold on
for i = 1:length(theta3)
THETA3 = theta3(i);
x = L1*cosd(THETA1) + L2*cosd(THETA1-THETA2) + L3*cosd(THETA1-THETA3);
y = L1*sind(THETA1) + L2*sind(THETA1-THETA2) + L3*sind(THETA1-THETA3);
plot(x,y)
end
hold off
xlabel('x')
ylabel('y')
title('Inverse Kinematic Plot of a 3-Bar Linkage')
Using the parfor-loop the code breaks down and my plot is completly empty:
L1 = 10;
L2 = 5;
L3 = 3;
theta1 = (0:5:90);
theta2 = (0:5:180);
theta3 = (0:5:180);
[THETA1,THETA2] = meshgrid(theta1,theta2);
figure
hold on
parfor i = 1:length(theta3)
THETA3 = theta3(i);
x = L1*cosd(THETA1) + L2*cosd(THETA1-THETA2) + L3*cosd(THETA1-THETA3);
y = L1*sind(THETA1) + L2*sind(THETA1-THETA2) + L3*sind(THETA1-THETA3);
plot(x,y)
end
hold off
xlabel('x')
ylabel('y')
title('Inverse Kinematic Plot of a 3-Bar Linkage')Mark Todiscohttps://la.mathworks.com/matlabcentral/profile/authors/8698384-mark-todiscotag:la.mathworks.com,2005:Question/4516442019-03-22T06:17:24Z2019-03-22T06:49:38Zproblem in writing codeRespected sir i have written following code according to formula given below
delta=0.02;
lamda=[0.01: 0.001 : 0.1];
p= lamda./delta;
q1=delta-lamda+lamada*exp(-delta./lamda);
plot(p,q2);
xlabel('p');
ylabel('q1');
error message
Undefined function or variable 'lamada'.
Error in tryq1 (line 4)
q=delta-lamda+lamada*exp(-delta./lamda);
Souvick royhttps://la.mathworks.com/matlabcentral/profile/authors/14032580-souvick-roytag:la.mathworks.com,2005:Question/4516392019-03-22T05:36:52Z2019-03-22T06:44:00ZHow to synchronize Arduino Due and Arduino Uno without data acquisition delay in Matlab??I have interfaced Arduino due board and Arduino Uno boards with Matlab GUI to acquire data streams real time. Arduino due board is operated at 3.3V and sensor is connected via SDA/SCL and Arduino Uno is operated at 5V and analog sensors are connected to the device. When I run the GUI program, I get real time data from arduino due but data coming from Arduino Uno will get delayed and the delay time is increased with the progress.
How can I synchronize the 2 devices to get rid of delay???
Kasun Samarawickramahttps://la.mathworks.com/matlabcentral/profile/authors/5523489-kasun-samarawickramatag:la.mathworks.com,2005:Question/4516482019-03-22T06:35:27Z2019-03-22T06:40:10Zundefined function 'a' in kmeans segmentation.How can i correct this?while i run the code for kmeans segmentation,i am getting an erron in line 2 of one code and a function error in the other.How to correct this?Sri Vasudha Bankupallehttps://la.mathworks.com/matlabcentral/profile/authors/15104479-sri-vasudha-bankupalletag:la.mathworks.com,2005:Question/913032013-10-24T04:17:46Z2019-03-22T06:35:00ZHow to convert a code from C language to Matlab?Dear all,
I have a code written in C language that detect the lines between cells in confocal images using the Watershed method. I want to use this C code in matlab. Is there any way to do so? Meshooohttps://la.mathworks.com/matlabcentral/profile/authors/178590-meshoootag:la.mathworks.com,2005:Question/4516472019-03-22T06:26:18Z2019-03-22T06:28:12Zhow to check whether a particular file is there in the datastore or not? i want to add 5 images in svm train and by using a webcam screenshot want to test whether that image exists in the the datastore or not. If it exist then result gives 1 and if not result will be zero.Kuljinder Singhhttps://la.mathworks.com/matlabcentral/profile/authors/11978380-kuljinder-singhtag:la.mathworks.com,2005:Question/4516212019-03-22T02:21:50Z2019-03-22T06:26:21ZDetermining the appropriate range for the given number.I want to know, if I have a number such as 1.5 and I have 120 equal segments of number-line from 0.00 to 6.00 how can I determine in which segment this number (in this case 1.5) can be placed. I know I can use 'if-elseif' but for checking 120 case with 'if-elseif' seems very difficult. Is there any other way to do it?Alok Kumar Dubeyhttps://la.mathworks.com/matlabcentral/profile/authors/10038159-alok-kumar-dubeytag:la.mathworks.com,2005:Question/4516362019-03-22T05:19:56Z2019-03-22T06:23:07Zconvert negative values to binary and backwhen doing the below line i get a data of values 0 and 1 of double datatype
data = randi([0,1], 1, 100);
How can i convert a vector of negative values to 0 and 1 of double datatype
Also i want to get the negative values back from the binary values
[-0.00153846153846154
0
-0.000769230769230769
-0.0126923076923077
0.00384615384615385
-0.00769230769230769
-0.0115384615384615
0.00461538461538462
-0.0173076923076923
0.00461538461538462
-0.000769230769230769
-0.00923076923076923]
few values
values are in the range -1 to 1Elysi Cochinhttps://la.mathworks.com/matlabcentral/profile/authors/3625227-elysi-cochintag:la.mathworks.com,2005:Question/4516292019-03-22T04:47:51Z2019-03-22T06:21:23ZChange sign of every second element of a vectorHi,
I want to change the sign of every second element in a vector, starting from element two. I tried the following code. Can someone explain why it does not work and help me to fix it? Thank you!
function newVector = change(v)
for i = 1:length(v)-1
newVector(i) = v(i);
newVector(i+1) = v(i+1)*-1;
end
v = newVector
endamhttps://la.mathworks.com/matlabcentral/profile/authors/14998149-amtag:la.mathworks.com,2005:Question/4516452019-03-22T06:19:18Z2019-03-22T06:19:18ZHow to draw a CIELAB color chart? Dear Matlab community,
I am new to Matlab. Would like to ask for help from Matlab experts.
I would like to draw a circular CIELAB color chart (as below) and mark my data points on it. Is it possible to do so in Matlab, and how?
Thank you! Sawhttps://la.mathworks.com/matlabcentral/profile/authors/13243794-sawtag:la.mathworks.com,2005:Question/4516432019-03-22T06:17:11Z2019-03-22T06:17:11Zcalculation of time bins in SpectrogramI have a signal signal of 20 sec. The samplaing frequency is 17Hz. The signal is shown in the below code:
fs=17;
f=.3; %Frequency of signal
t=0:1/fs:339*1/fs;
y=10*sin(2*pi*f*t);
I have calculated the spectrogram of the above signal for time-frequency analysis with the help of below code:
windowsize =256;
window =hanning(windowsize);
nfft = windowsize;
%noverlap = windowsize-1;
noverlap = windowsize/2;
[S,F,T] = spectrogram(y,window,noverlap,nfft,fs);
figure;
imagesc(T,F,log10(abs(S)));
colorbar
set(gca,'YDir','Normal')
xlabel('Time (sec.)')
ylabel('Freq (Hz)')
title('Short-time Fourier Transform spectrum')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
When I run this code, I get the spectrogram plot where the time axis ranges from 0 to around 8 sec. Also the T variable has single value as T=7.529411. I want to understand how the T value changes with the Window size. My actual signal length is 20 sec. but why it's showing for around 8 sec only in spectrogram. I have used 50% overlap.
Deepak kumarhttps://la.mathworks.com/matlabcentral/profile/authors/12312247-deepak-kumartag:la.mathworks.com,2005:Question/4516352019-03-22T05:16:01Z2019-03-22T06:15:53ZCheck if element in array are square of each otherHello,
I have a problem where I have to find possible squares in an array. For example [7 5 49] or [49 5 7] is true since 7 squared is 49, but [11 13 25] should return false.
Is there a way to do it better than a nested loop?
Thank you!
function y = isItSquared(x)
y = false;
for i = 1:length(x)
for j = i+1:length(x)
if x(i)^2 == x(j) || x(i) == x(j)^2
y = true
break
end
end
end
amhttps://la.mathworks.com/matlabcentral/profile/authors/14998149-amtag:la.mathworks.com,2005:Question/4516422019-03-22T06:08:18Z2019-03-22T06:15:24ZCheck if vector is increasing monotonely or just increasingHello,
I have to check if the elements in a vector are in increasing order (or even equal to each other). In that case the function should return true. But if the following element is smaller, it should return false.
The function below doesn't pass tests if my vector is not monotonous, and I can't understand why?
function t = is_increasing(x)
k = 1
for k = 1:(length(x)-1)
if x(k+1) - x(k) > 0 || x(k+1) - x(k) == 0
t = true
k = k + 1
else
t = false
return
end
end
endamhttps://la.mathworks.com/matlabcentral/profile/authors/14998149-amtag:la.mathworks.com,2005:Question/4494122019-03-11T12:38:55Z2019-03-22T06:09:45ZSerial Communication with ArduinoHello,
I want that a serial communication with an Arduino.
They can communicate. I did it over the serial Connection without addons.
As next step I want to send with MatLab a "start send" message to the Arduino. At the moment the Arduino receive the message the controller should start the programm to send the data to matLab.
Sadly it doesnt work.
I hope that you can help me!
Thanks Lisa
Lisa-Sophie Baierhttps://la.mathworks.com/matlabcentral/profile/authors/14176571-lisa-sophie-baiertag:la.mathworks.com,2005:Question/4516412019-03-22T06:03:25Z2019-03-22T06:03:25Zgetting so many errors in the codeno matter how many times i try to correct the code,i still get so many errors could some one help me out in correcting the codes?Sri Vasudha Bankupallehttps://la.mathworks.com/matlabcentral/profile/authors/15104479-sri-vasudha-bankupalletag:la.mathworks.com,2005:Question/4516402019-03-22T05:59:18Z2019-03-22T05:59:18Zi need to find out 5 feature in emg signal i need to find out 5 feature in emg signals: slop sign change, zero crossing, waveform length, moving average and mean absolute value.Ali Asgharhttps://la.mathworks.com/matlabcentral/profile/authors/12644613-ali-asghartag:la.mathworks.com,2005:Question/4516282019-03-22T04:22:49Z2019-03-22T05:46:59Zioshwsetup verify configuration of your ios device I am trying to connect/verify my iphone to matlab. I was able to provision my iphone using xcode and run and create the app on my iphone using xcode but I am trying the audio example in matlab and need to verify my ios device. but I am getting this error when following the steps of verifing configuration of my ios device. Any help please.
Build App
Planning build note: Constructing build description Build system information error: No profiles for 'com.MathWorksExample.WJpQU4mUYW1aYzAT2ZJ5' were found: Xcode couldn't find any iOS App Development provisioning profiles matching 'com.MathWorksExample.WJpQU4mUYW1aYzAT2ZJ5'. Automatic signing is disabled and unable to generate a profile. To enable automatic signing, pass -allowProvisioningUpdates to xcodebuild. (in target 'TestApp') ** BUILD FAILED **
sherif salemhttps://la.mathworks.com/matlabcentral/profile/authors/7866750-sherif-salemtag:la.mathworks.com,2005:Question/4510622019-03-19T23:47:03Z2019-03-22T05:44:30ZExtracting matrix and making 2D plotI made 2-D color map by using those datasets below
latmat.mat... latitude data (171*171)
lonmat.mat...longitude data(171*171)
CH4.mat.... CH4 emission data (171*171)
Coding is as follows,
figure
latlim=[min(latmat(:)) max(latmat(:))]
lonlim=[min(lonmat(:)) max(lonmat(:))]
ax=usamap(latlim,lonlim);
title('Air Pollution Map');
surfm(latmat,lonmat,CH4)
states=shaperead('usastatehi',...
'UseGeoCoords',true,'BoundingBox',[lonlim',latlim']);
geoshow(ax,states,'FaceColor','none')
contourcbar
And got this figure below.
However, I would like to make a map within those ranges below.
70W<Longitude<75W
40N<Latitude<43N
How can I extract the datasets and make a colormap?Chihiro Omorihttps://la.mathworks.com/matlabcentral/profile/authors/10829510-chihiro-omori