https://es.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — New Questions2019-09-22T22:38:25Ztag:es.mathworks.com,2005:Question/4815932019-09-22T21:37:34Z2019-09-22T22:38:25ZFind inverse of a cdf so as to sample xI have a cdf calculated as follows:
mu = 0;
var = 1;
x = -10:0.01:10;
y = cumtrapz((2*pi*(var))^(-0.5)* exp(-((x-mu).^2)/(2*(var))));
This gives the cdf of my probability distribution function (pdf): (2*pi*(var))^(-0.5)* exp(-((x-mu).^2)/(2*(var)))
But i want to sample the values of x randomly for this pdf. So I've created the cdf stored in variable y.
If i can find the inverse cdf, then i can uniformly select y values and then calculate using inverse cdf the corresponding x values that become my sample.
with the inverse function of the cdf, i want to get x in terms of y,
eg, y = F(x)
then x = Finverse(y)
like in figure:
I want to pass in y in the figure to Finverse(y) which is inverse of cdf, and then i can get x as:
x = Finverse(y)
But, i've tried many methods till now, but none seem to help.
i've tried to use :
i = erfinv(y)
but this gives me values as vector, but i need function so that i can pass in the values of y to get x. Please help.Aishwarya Radhakrishnanhttps://es.mathworks.com/matlabcentral/profile/authors/12911762-aishwarya-radhakrishnantag:es.mathworks.com,2005:Question/4815892019-09-22T21:03:26Z2019-09-22T22:37:57ZUndefined function or variable using ODE45I'm having trouble with defining an independent variable in matlab. I am getting the error, 'undefined function or variable 'Y'. Y is the variable I am trying to solve for.
%elementary rate law
FA0=10; %mol/min
W=100; %KG
a=.008; %kg^-1
k1C=2; %L/kg cat/min
K1C=.2; %mol/L
k2D=.4; %L/kg cat/min
k3E=5; %L/mol^2/kg cat/min
kc=1; %L/kg cat/min
v=16.67; %L/min
Fa=Y(1);
Fb=Y(2);
Fc=Y(3);
Fd=Y(4);
Fe=Y(5);
y=Y(6);
CT0=FA0;
FT=Fa+Fb+Fc+Fd+Fe;
Ca=CT0*(Fa/FT)*y;
Cb=CT0*(Fb/FT)*y;
Cc=CT0*(Fc/FT)*y;
Cd=CT0*(Fd/FT)*y;
Ce=CT0*(Fe/FT)*y;
r1C=k1C*(Ca-(Cb*Cc/K1C));
r2D=k2D*Cd;
r3E=k3E*Cd*(Ce^2);
ra=-r1C-r2D;
rb=r1C;
rc=r1C-r3E;
rd=r2D-.5*r3E;
re=r3E;
dFadw=ra;
dFbdw=rb;
dFcdw=rc;
dFddw=rd;
dFedw=re;
dydw=-a*FT/(2*FT0*y);
fun=@(w,Y)[dFadw;dFbdw;dFcdw;dFddw;dFedw,dydw];
wspan=0:1:100;
x0=[10;0;0;0;0;1];
[T,X] = ode45(fun,wspan,x0)Andrew Knighthttps://es.mathworks.com/matlabcentral/profile/authors/13653326-andrew-knighttag:es.mathworks.com,2005:Question/4815472019-09-22T11:10:57Z2019-09-22T22:37:16ZODE 6 Model equation
%% Minimal Glucose insulin 6 dimension ode model
% Name: Aniruddha
% Date: 16.09.2019
% 6 model ode differential equation:
%dG(t)/dt=Gin-f2(G(t))-f3(G(t))f4(Ii(t))+f5(x(3)) %G(t)= mass of glucose
%dIp(t)/dt=f1(G(t))-E[(Ip(t)/Vp)-(Ii(t)/Vi)]-Ip(t)/tp
%Ip(t)=mass of insulin in plasma
%dIi(t)/dt=E[(Ip(t)/Vp)-(Ii(t)/Vi)]-Ip(t)/ti
%Ii(t)= mass of insulin in intercellulr space
%dx1(t)/dt=3/td(Ip(t)-x1(t))
%dx2(t)/dt=3/td(x1(t)-x2(t))
%dx3(t)/dt=3/td(x2(t)-x3(t))
% Mapping G=y(1), Ip=y(2),Ii=y(3),x1=y(4),x2=y(5),x3=y(6)
%% clean up:
clc;
%% parameter values
p.Vp=3; % plasma insulin distribution volume
p.Vi=11;% Effective volume of intercellular space
p.Vg=10;
p.E=0.2;%Diffusion transfer rate
p.tp=6; % insulin degradation time constant in plasma
p.ti=100;% insulin degradation time constant in intercellular spaces
p.td=36;
p.Rm=210;
p.a1=300;
p.C1=2000;
p.Ub=72;
p.C2=144;
p.C3=1000;
p.U0=40;
p.Um=940;
p.b8=1.77;
p.C4=80;
p.Rg=180;
p.a2=0.29;
p.C5=26;
p.Gin=3;
%% Solve the ode:
tspan=[0 200];
y0=[0;0;0;0;0;0]';
[T,Y]=ode45(@model,tspan,y0,[],p);
% Rewrite the state variables:
G=Y(:,1);
Ip=Y(:,2);
Ii=Y(:,3);
x1=Y(:,4);
x2=Y(:,5);
x3=Y(:,6);
%% Illustration:
figure(1)
subplot(1,6,1)
plot(T,G)
xlabel('time [min]')
ylabel('mass of glucose ')
grid on;
subplot(1,6,2)
plot(T,Ip)
xlabel('time [min]')
ylabel('mass of insulin in plasma ')
grid on;
subplot(1,6,3)
plot(T,Ii)
xlabel('time [min]')
ylabel('mass of insulin in intercellular spaces ')
grid on;
subplot(1,6,4)
plot(T,x1)
xlabel('time [min]')
ylabel('x1 ')
grid on;
subplot(1,6,5)
plot(T,x2)
xlabel('time [min]')
ylabel('x2 ')
grid on;
subplot(1,6,6)
plot(T,x3)
xlabel('time [min]')
ylabel('x3 ')
grid on;
function ds=model(t,y,p)
G=y(1);
Ip=y(2);
Ii=y(3);
x1=y(4);
x2=y(5);
x3=y(6);
%% 6 model equation:
f1(G)=p.Rm/(1+exp((p.C1-G/p.Vg)/p.a1));
f2(G)=(p.Ub)*(1-exp(-G/p.C2*p.Vg));
f3(G)=G/p.C3*p.Vg;
f4(Ii)=p.U0 + (p.Um-p.U0)/1+exp(-p.b8(Ii/p.C4(1/Vi + 1/Eti)));
f5(x3)= p.Rg/1+exp(p.a2(x3/p.Vp -p.C5));
dG= p.Gin-f2(G)-f3(G)*f4(Ii)+f5(x3); %%ODE for mass of glucose
dIp= f1(G)-p.E*((Ip/p.Vp)-(Ii/p.Vi))-Ip/p.tp; %%ODE for mass of insulin in plasma
dIi=p.E*((Ip/p.Vp)-(Ii/p.Vi))-Ip/p.ti; %% ODE for mass of insulin in intercellular spaces
dx1=(3/p.td)*(Ip-x1);
dx2=(3/p.td)*(x1-x2);
dx3=(3/p.td)*(x2-x3);
ds=[dG,dIp,dIi,dx1,dx2,dx3]';
end
I am getting error in ode45 Aniruddh Deshmukhhttps://es.mathworks.com/matlabcentral/profile/authors/15832735-aniruddh-deshmukhtag:es.mathworks.com,2005:Question/4815522019-09-22T11:46:41Z2019-09-22T22:32:40ZHow to use cellstr() without losing whitespace character?Hi,
i need cellstr NOT to delete ending whitespace. Some strings have whitespace and i need those to stay alive.
Btw it's weird that cellstr does not perform a full strtrim but only deletes ending whitespace character.
{' test '} would do the job for just 1 string, how do i perform this on hundrets without a loop?
What is the best way to do that?
thxMichael Kainzbauerhttps://es.mathworks.com/matlabcentral/profile/authors/8839478-michael-kainzbauertag:es.mathworks.com,2005:Question/4815972019-09-22T22:27:59Z2019-09-22T22:28:48ZUsing fprintf to print in text fileHi all,
I'm very very unfamiliar with MATLAB. I've been trying to write a code that can neatly organize the data that is stored in certain variables into a text file.
What I want the final product to look like is this:
Each column is stored in separate variables (e.g. nodeID=[1;2;3;4], X=[0;0;120;120], etc)
I've been trying to use frpintf function and got to where there is a breakline between the column titles and the numbers.
I'd like to know how to evenly space these numbers as shown in the picture. Currently I've been adding spaces (using ' ') via fprintf but this gives me something that looks like below:
the code i have is the following (it's embarrassing really):
here nNode = 4,
for i = 1:nNode
fprintf(txt,'\n');
fprintf(txt, '%d', nodeID(i));
fprintf(txt, ' ');
fprintf(txt, '%.2f', X(i));
fprintf(txt, ' ');
fprintf(txt, '%.2f', Y(i));
fprintf(txt, ' ');
fprintf(txt, '%.3f', fx(i));
fprintf(txt, ' ');
fprintf(txt, '%.3f', fy(i));
end
Is there a more efficient way to go about this issue?
Thanks a bunch :)Sung Yeob Limhttps://es.mathworks.com/matlabcentral/profile/authors/2996232-sung-yeob-limtag:es.mathworks.com,2005:Question/4815212019-09-22T02:19:51Z2019-09-22T22:28:13ZFormat number in the same format as dispI want to format number to the string with the same format as used by disp to output numbers. So I want to write function my_format that would take number and output same string as disp. I don't need new lines, just correctly formatted number. For example
>> format
>> pi
ans =
3.1416
>> my_format(pi)
ans =
'3.1416'
>> format long
>> pi
ans =
3.141592653589793
>> my_format(pi)
ans =
'3.141592653589793'
Anton Gribovskiyhttps://es.mathworks.com/matlabcentral/profile/authors/9643543-anton-gribovskiytag:es.mathworks.com,2005:Question/4815802019-09-22T19:19:37Z2019-09-22T22:25:34Zhow to handle multiple device ?i want to create an IoT project that use several nodeMCU. can i send data from several device to 1 channel ? or i should create channel for every single device ? or is there any recommendations ?Andino Faturahmanhttps://es.mathworks.com/matlabcentral/profile/authors/16321012-andino-faturahmantag:es.mathworks.com,2005:Question/4815962019-09-22T22:16:09Z2019-09-22T22:16:09ZHow can I create a subplot of ode45 for a mass spring damper where the two plots have a different k value?I'm new to MATLAB and i'm trying to create two subplots side by side, where the only difference is the 'k' value in the mass spring damper equation is different.
Here is the code:
function zprime= msdfunc(t,z)
m = 4; b = 0.25; k = 2;
zprime=[z(2);-(b/m)*z(2)-(k/m)*z(1);];
end
tspan=[0, 60];
y0=[0, 4];
[t, y]=ode45(@msdfunc, tspan, y0);
plot(t, y);
I need to plot the equation for k=2 and k=4.
Thanks in advanceCaleb Berrimanhttps://es.mathworks.com/matlabcentral/profile/authors/16059095-caleb-berrimantag:es.mathworks.com,2005:Question/4429222019-02-03T13:56:16Z2019-09-22T22:12:02ZParrot Mambo drone connecting problem Hello,
I've been trying to connect my Parrot Mambo drone to my Mac using BlueTooth but I still can't see it in the devices list. It can connect properly to my iPhone and my PC (Windows).
I've tried all the troubleshooting tips on The Mathworks webstite: https://www.mathworks.com/help/supportpkg/parrot/ug/minidrone-not-found-by-bluetooth-scan-1.html
but still I can't see in the devices in the BlueTooth list on my Mac. I also contacted Apple support and I've done SMC and PRAM reset.
I would really appreciate your help.
Thanks. Omar Shadeedhttps://es.mathworks.com/matlabcentral/profile/authors/11301581-omar-shadeedtag:es.mathworks.com,2005:Question/4815952019-09-22T21:51:12Z2019-09-22T21:51:12ZCreate a matrix from some given matricesI have this matrix to implement. Where user would define the value of dimensions ( p and N).
what would be the most efficient way to doing this in matlab. Tanvir Hossainhttps://es.mathworks.com/matlabcentral/profile/authors/8226802-tanvir-hossaintag:es.mathworks.com,2005:Question/4815942019-09-22T21:42:34Z2019-09-22T21:42:34ZIndex exceeds matrix dimensions.I've been fixing this code, now i have a problem in line 29, that says "Index exceeds matrix dimensions." how can I fix it ?
%T=1/pi;
t=-pi:pi/99:pi;
A=2;
w0=(2.*pi)*(1./t);
f=A*sin(t)
f1=abs(f);
figure(1)
plot(t,f1)
%serie de fourier
%hold on
for n=1:2:40
y=f1+((2*A)/pi)*(sin(n*t)/n);
plot(t,y) ;pause(.2)
%hold off;
end
figure(2)
%fft
y2=f1+((2*A)/pi)*(sin(20*t)/20);
Fs=1500;
Ts=1./Fs;
L=1500;
tl=(0:L-1).*Ts;
y4=fft(y2);
P2=abs(y4./L);
P1=P2(1:L./2+1);
P1(2:end-1)=2*P1(2:end-1)
g= Fs*(0:(L/2))/L;
plot(handles.axes2,g,P1,'r')Carlos Antonio Hernández Guerrerohttps://es.mathworks.com/matlabcentral/profile/authors/14902957-carlos-antonio-hernandez-guerrerotag:es.mathworks.com,2005:Question/4815922019-09-22T21:28:57Z2019-09-22T21:28:57ZIs there some kind of input map size limitation that could explain why caxis or CLim do not work?Hello,
I've written a script that turns contour elevation data into a DTM grid and plots the slope at each grid point in 2D:
surf(xi,yi,slope, 'LineStyle', 'none'), colorbar;
colormap jet
title('Slope')
xlabel('Longitude')
ylabel('Latitude')
zlabel('slope')
view(2)
I would like to change the coloubar scale. I tried CLim and caxis, which work when the map is small enough. They don't when the map is several km wide. Is there some kind of limitation in matlab that could explain that? Are there any alternatives to do that?
Thank youNPhttps://es.mathworks.com/matlabcentral/profile/authors/15681215-nptag:es.mathworks.com,2005:Question/4815792019-09-22T19:04:54Z2019-09-22T21:22:00ZSimple fixed-point iteration methodMy task is to implement (simple) fixed-point interation.
So far, I've got the following and I keep receiving error Undefined function 'fixedpoint' for input arguments of type 'function_handle'.
(I'm new in Matlab, so there may be both syntactical or semantical errors...)
function [ x ] = fixedpoint(g,I,y,tol,m)
% input: g, I, y, tol, max
% g - function
% I - interval
% y - starting point
% tol - tolerance (error)
% m - maximal number of iterations
% x - approximate solution
a=I(1);b=I(2);
if(y<a | y>b)
error('The starting iteration does not lie in I.')
end
x=y;
gx=g(y);
while(abs(x-gx)>tol & m>0)
if(gx<a | gx>b)
error('The point g(x) does not lie in I.')
end
y=x;
x=g(y);
m=m-1;
endJohn Smithhttps://es.mathworks.com/matlabcentral/profile/authors/16318507-john-smithtag:es.mathworks.com,2005:Question/4815912019-09-22T21:12:26Z2019-09-22T21:13:48ZKeep Variable Editor Window Open Without Having Any Variables in WorkspaceI just want to keep the Variables Editor (not the Workspace window) open at all times to keep my desktop layout neat and tidy without having my layout auto resize everything everytime I click on a variable to ensure data population of a table during development of a new script.B. Griffithshttps://es.mathworks.com/matlabcentral/profile/authors/16135970-b-griffithstag:es.mathworks.com,2005:Question/4815872019-09-22T20:58:22Z2019-09-22T21:10:52Zmatrix dimension must agreeI have this code and i wanna plot the fourier serie of my signal in frecuency, I've been traying to plot it but in the line 25 i have an error "matrix dimension mut agree" and i can't fix it. could someone help me with this ?
%T=1/pi;
t=-pi:pi/99:pi;
A=2;
w0=(2.*pi)*(1./t);
f=A*sin(t)
f1=abs(f);
figure(1)
plot(t,f1)
%serie de fourier
%hold on
for n=1:2:40
y=f1+((2*A)/pi)*(sin(n*t)/n);
plot(t,y) ;pause(.2)
%hold off;
end
figure(2)
%fft
Fs=5*t;
Ts=1./Fs;
L=1500;
tl=(0:L-1).*Ts;
y4=fft(f1);
P2=abs(y4/L);
P1=P2(1:L/2+1);
P1(2:end-1)=2*P1(2:end-1)
g= Fs*(0:(L/2))/L;
plot(handles.axes2,g,P1,'r')Carlos Antonio Hernández Guerrerohttps://es.mathworks.com/matlabcentral/profile/authors/14902957-carlos-antonio-hernandez-guerrerotag:es.mathworks.com,2005:Question/4815842019-09-22T20:47:44Z2019-09-22T21:08:37ZCommunicate with worker through clientHello!
I have an app (app designer/GUIDE) which calls a function that looks something like this
function func()
spmd
switch labindex
case 1
while (true)
% some code...
end
case 2
while (true)
% some code...
end
end
end
end
and I would like to be able to break out of the while loop for each workers of the spmd with a click of a button in the app, which means I have to send data from the client to the workers.
I know I can easily send data from the workers to the client, but I'm not sure about the reverse direction.
Please help, thanks!guy sharonhttps://es.mathworks.com/matlabcentral/profile/authors/9368487-guy-sharontag:es.mathworks.com,2005:Question/4815902019-09-22T21:08:31Z2019-09-22T21:08:31ZMatlab download very slowI bought a brand new macbook and I've tried to download MatLab on to it but its literally taken 2 hours to get to 5%. Is there anything i can do to speed it up????Maryam Sharifhttps://es.mathworks.com/matlabcentral/profile/authors/16320427-maryam-shariftag:es.mathworks.com,2005:Question/4815862019-09-22T20:57:42Z2019-09-22T20:57:42ZWhy is my code not working?I'm working on a project dealing with a function for a damped harmonic oscillator. I've found the derivate of this function to plot the velocities. I'm being asked to "Superimpose the respective velocities estimating them using a numerical approach." I'm not sure why the code I'm using won't run. I get no errors; the graph just never appears. I've linked the original m file. Any help is much appreciated!
Derek Gabaldonhttps://es.mathworks.com/matlabcentral/profile/authors/16035797-derek-gabaldontag:es.mathworks.com,2005:Question/2433022015-09-16T09:29:54Z2019-09-22T20:55:52ZHow to determine average and standard deviation of y axis values for corresponding bin of x axis?
Sir i have two data series say
a b
25.36737061 -27.47956892
20.54391479 -23.68162398
16.76391602 -16.65254461
9.47177124 -19.20600915
16.25158691 -18.56570783
4.462646484 -14.39363913
7.785919189 -14.98048449
12.27481079 -18.49125231
4.851806641 -19.91135093
2.111236572 -5.049334665
-1.457702637 -6.51219601
1.85055542 -1.299793246
and i want to plot for bin width of 'a' (say 5,10,15 etc) with the corresponding average and standard deviation of b. Please help me with a easy way since the series are very large?trailokyahttps://es.mathworks.com/matlabcentral/profile/authors/4301200-trailokyatag:es.mathworks.com,2005:Question/4815852019-09-22T20:54:36Z2019-09-22T20:54:36ZHow can I parse A2L file Function Section ?Dear Users,
I would like to parse a2l file function interaction. But I could not be succussful.
I have no experience on string processing side of Matlab. Could you help me how can I get function infromations from a2l file?
Example A2L Function Section:
/begin FUNCTION
Vehicle
"0.0.1 Function Name"
/begin DEF_CHARACTERISTIC
Label_1 Label_2 Label_3 Label_4
/end DEF_CHARACTERISTIC
/begin IN_MEASUREMENT
Label_5
/end IN_MEASUREMENT
/begin OUT_MEASUREMENT
Label_7 Label_8 Label_9
/end OUT_MEASUREMENT
/begin LOC_MEASUREMENT
Mp_1 Mp_2 Mp_3 Mp_4 Mp_5
/end LOC_MEASUREMENT
FUNCTION_VERSION "0.0.1"
/end FUNCTION
My Code to READ A2L FUNCTION NAME AND FUNCTION DESCRIPTION
index_number=zeros(k,1);
index_number_a=zeros(k,1);
mm=0;
nn=0;
for i=1:1:k
if (a(i)=="/begin FUNCTION")
nn=i;
index_number_a(i)=nn;
end
end
for kk=1:1:k
if (a(kk)=="/begin DEF_CHARACTERISTIC")
mm=kk;
index_number(kk)=mm;
end
end
index_number_anew=find(index_number_a);
index_number_new=find(index_number);
num=length(index_number_anew);
for pp=1:1:num
t=index_number_anew(pp);
r=index_number_new(pp);
temp=r-t;
for counter=(t+1):1:(r-1)
temp1=strfind(a(counter),'"');
temp2=strcmp(a(counter),"");
if (~isempty(a(counter)) && isempty(temp1)&&(temp2==0))
FunctionNaming(counter)=a(counter);
end
if (~isempty(a(counter)) && ~isempty(temp1)&&(temp2==0))
FunctionDescription1(counter)=a(counter);
end
end
end
Could you offer a suggestion to read a2l file on matlab I will be appreciate to you.ilker ozturkhttps://es.mathworks.com/matlabcentral/profile/authors/3609786-ilker-ozturktag:es.mathworks.com,2005:Question/4814712019-09-21T14:22:40Z2019-09-22T20:45:42Zhow we store video frames in firebase from matlab?how we can store video frames form matlab to fire base?zakir khanhttps://es.mathworks.com/matlabcentral/profile/authors/16312286-zakir-khantag:es.mathworks.com,2005:Question/4814732019-09-21T15:21:58Z2019-09-22T20:45:11Zcan we store the image from matab to thingspeak?can we store the image from matab to thingspeak?zakir khanhttps://es.mathworks.com/matlabcentral/profile/authors/16312286-zakir-khantag:es.mathworks.com,2005:Question/4815832019-09-22T20:42:55Z2019-09-22T20:42:55Zproblems in saving filesHi!
I am experiencing problems in saving matlab files on my usb sticks. All other files are possible to save as word..etc
Muazma Alihttps://es.mathworks.com/matlabcentral/profile/authors/11571852-muazma-alitag:es.mathworks.com,2005:Question/4815152019-09-22T00:49:25Z2019-09-22T20:36:10ZExtract a heart beat from a recording (sound file).Hi there
I have a sound file that contains heart beat signal. The nise is very load and the signal is very quit (but harmonic). How can i extract the herat beat signal using matlab ?
i used this code to filter the signal, but didnot work.
[f,fs] = audioread('Recording (17).m4a');
pOrig = audioplayer(f,fs);
%pOrig.play;
%%plot audio channels
N = size(f,1); % determine total number of samples in audio file.
figure
stem(1:N, f(:,1));
title('Channel');
% plot the spectrum using fft
df = fs / N;
w = (-(N/2):(N/2)-1)*df;
y = fft(f(:,1), N) / N; %NORMALISATION
y2 = fftshift(y);
figure;
plot(w,abs(y2));
%plot the spectrum using Pwelch
[pxx, freq] = pwelch(y, [],[],[],fs);
plot(freq,10*(pxx),'k','linewidth',1.2);
xlabel('Frequency (Hz)');
ylabel('Spectral Density (Hz^{-1})');
%deign a bandpass filter that filters out between 700 to 1200 Hz
n = 7;
beginFreq = 700 / (fs/2);
endFreq = (11000 / (fs/2));
[b,a] = butter(n, [beginFreq, endFreq], 'bandpass');
[H,W] = freqz(b,a,n);
figure(3);
plot(angle(H))
figure(4);
plot(20*log10(abs(H)));
%%filter the signal
fout = filter(b,a,f);
%%contruct audioplayer object and play
p = audioplayer(fout, fs);
p.play;
%audiowrite('filtered file', fout,fs)
Ahmad Alenezihttps://es.mathworks.com/matlabcentral/profile/authors/15695060-ahmad-alenezitag:es.mathworks.com,2005:Question/4553952019-04-09T21:41:11Z2019-09-22T20:19:09Znext prime number using While loopsWe have to write a function called next_prime that takes a scalar positive integer input n. Use a while-loop to find and return k, the smallest prime number that is greater than n. we may use isprime function. plz help..Xenium Adilhttps://es.mathworks.com/matlabcentral/profile/authors/15258520-xenium-adiltag:es.mathworks.com,2005:Question/4815132019-09-22T00:28:13Z2019-09-22T20:16:28Zcftool "Not enough input arguments"Hi,
I've been using MATLAB for quite a long time. However, in the new version (2019b) on Mac OSX, I'm facing an odd problem. I'm trying to use the cftool simply for fitting a gaussian function on a bell-shaped data (say x is my 1D array of independent variable, and y is another 1D array of the same size for the data). The fitting fails and an error message is displayed saying "Not enough input arguments". I also tried fitting other functions on the data and it seems that the problem is not limited to the gaussian fit and it similarly occurs for custom equation, exponential, Fourier, rational, power and sum of sines.
Nevertheless, the fitting on the same data is easily done by an old version on the same system (2016b). To resolve the issue I tried various things, but none worked.
I really appreciate any ideas on how to resolve this issue.
Best, dariush abhttps://es.mathworks.com/matlabcentral/profile/authors/5058525-dariush-abtag:es.mathworks.com,2005:Question/4815822019-09-22T20:16:13Z2019-09-22T20:16:13ZError using ode45Defined function named: stringpendulum_function_1
function [ dy ] = stringpendulum_function_1( t,y )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
% These parameters should be actually in a different file and defined as
% global variables to be shared (since this is small simulation we can
% afford to spend time in trivially defining them every time)
m1=0.38;
m2 = 0.03;
M = m1+m2;
l1 = 0.5;
l2 = 0.3;
k = 10; %% unit
%
rm=0.007;
ko=25;
k1=150;
g=9.81;
zeta=0.002;
%
%Btheta=2*zeta*sqrt(m^2*g*l^3);
%Br=2*zeta*sqrt(m*(ko+k1*y(3)^2))*0;
dy = zeros(6,1);
% theta1 = y(1)
% theta1(dot) = y(2)
% theta1(dubledot) = dy(2)
% theta2 = y(3)
% theta2(dot) = y(4)
% theta2(double dot) = dy(4)
% x = y(5)
% x(dot) = y(6)
% x(doubledot) = dy(6)
dy(1) = y(2);
dy(2) = (m2*l2*(l1+y(5))*y(4)*y(4)*sin(y(3)-y(1))-m2*l2*(l1+y(5))*dy(4)*dy(4)*cos(y(3)-y(1))-2*(l1+y(5))*y(6)*y(2)*(m1+m2)-(m1+m2)*g*sin(y(1))*(l1+y(5)))/((m1+m2)*y(5));
dy(3) = y(4);
dy(4) = (-m2*dy(6)*dy(6)*l2*sin(y(3)-y(1))-m2*(l1+y(5))*l2*dy(6)*cos(y(3)-y(1))-m2*l2*(l1+x)*y(2)*y(2)*sin(y(3)-y(1))-m2*l2*g*sin(y(3)))/(m2*l2*l2);
dy(5) = y(6);
dy(6) = ((m1+m2)*g*cos(y(1)-k*y(5)+(l1+x)*y(2)*y(2)*(m1+m2)-m2*l2*dy(4)*dy(4)*sin(dy(3)-dy(1))-m2*l2*y(4)*y(4)*cos(y(3)-y(1))+2*m2*l2*y(2)*y(4)*cos(y(3)-y(1))))/M;
end
Calling and plotting the returned values here:
clc;
clear all;
% resolution 0 to 10s in 1000 steps
time = linspace(0,10,1000)';
% Initial Conditions
IC = [pi/5; 0; pi/18; 0; 0.2; 0];
% Solve using ode45
[t,y] = ode45('stringpendulum_function_1',time,IC);
%[t,y] = ode45('stringpendulum_function_1',time,IC);
%{
%%Plot of generalised coordinates w.r.t. time
plot(t,y(:,1),'r')
hold on
plot(t,y(:,3),'b')
title('Pendulum with Non-Linear Spring');
xlabel('Time t');
ylabel('Solution y');
legend('theta','r')
%}
%% animation
figure;
O =[0 0];% origin or pivot point
axis(gca,'equal');% aspect ratio of the plot
axis([-0.6 0.6 -0.75 0.2]); % XY bounds
grid on;
%% Loop for animation
for i = 1:length(t)
% mass point
P1 = y(i,5)*[sin(y(i,1)), -cos(y(i,1))];
P2 = [P1(1) + 0.3*sin(y(i,3)), P1(2) - 0.3*sin(y(i,3))];
% circle at origin or pivot point
%origincircle = viscircles(O,0.001);
% Pendulum String joining pivot and current solution
pendulum1 = line([O(1) P(1)],[O(2) P(2)], 'LineWidth',5);
pendulum2 = line([P1(1) P2(1)], [P1(2) P2(2)]);
bob1 = line([P1(1) P1(1)],[P1(2) P1(2)], 'Marker','o','MarkerSize',25,'MarkerFaceColor','r');
bob2 = line([P2(1) P2(1)],[P2(2) P2(2)], 'Marker','o','MarkerSize',25,'MarkerFaceColor','b');
% ball
%ball = viscircles(P, 0.007);
% time interval to update the plot
pause(0.05);
%clear screen of previous pendulum position
if i<length(t)
%delete(origincircle);
delete(pendulum1);
delete(pendulum2);
delete(bob1);
delete(bob2);
%delete(ball);
end
end
Error message:
Error in stringpendulum_function_1 (line 37)
dy(4) =
(-m2*dy(6)*dy(6)*l2*sin(y(3)-y(1))-m2*(l1+y(5))*l2*dy(6)*cos(y(3)-y(1))-m2*l2*(l1+x)*y(2)*y(2)*sin(y(3)-y(1))-m2*l2*g*sin(y(3)))/(m2*l2*l2);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in DoublePendulumExtensible (line 10)
[t,y] = ode45('stringpendulum_function_1',time,IC);
Saurabh Kumarhttps://es.mathworks.com/matlabcentral/profile/authors/11109599-saurabh-kumartag:es.mathworks.com,2005:Question/4815642019-09-22T15:21:05Z2019-09-22T20:13:42ZWhat is the best way to set up a nested for loop?Hi,
I need help creating an efficient, nested for-loop. I have to run through a couple of equations on a few of variables but need to know the best way to increment these variables and to store their new values.
Thanks,
SteveSteven DiMarcohttps://es.mathworks.com/matlabcentral/profile/authors/14099673-steven-dimarcotag:es.mathworks.com,2005:Question/4815772019-09-22T17:53:04Z2019-09-22T19:58:08Zhow to number every val in a cell array?Hi all,
I have a 7-D cell array doing with 7 variables having from 1 -15 values each.
The result i am taking has the following form.
A 7-D array with val(:,:,1:15,1:5,1:7,1:8,1:9) . All the possible combinations of 7 variables are 37800.
S i want to create an array or number them in order to identify which combination corresponds to which result.
For example val(:,:,1,1,1,1,1) is case 1.
Thank you very much
Ilias Minashttps://es.mathworks.com/matlabcentral/profile/authors/13907044-ilias-minastag:es.mathworks.com,2005:Question/4815702019-09-22T16:10:01Z2019-09-22T19:50:21Zgraph and conncomp examplesIn the example given for conncomp it has this:
graph([1 1 4],[2 3 5],[1 1 1],6);
I do not understand how this leads to the graph which is displayed. The documentation for graph is not clear about this either. Can anyone explain how graph actually operates in this case in a really simple way?Pa342https://es.mathworks.com/matlabcentral/profile/authors/6626547-pa342tag:es.mathworks.com,2005:Question/4587922019-04-26T19:05:46Z2019-09-22T19:37:01ZTranspose/combine several variables using csvwrite or writematrixI have several variables that are in row form. I would like to write a script that will transpose these variables into column form and then combine write them into one csv file with each variable in a separate row. I have been able to export them individually in row form using csvwrite, but I'm not sure if I'm able to manipulate and combine variables with this or if I need to use writematrix instead. However, when I try to use this, it gives me the error: Undefined function or variable 'writematrix'.Erika Johhttps://es.mathworks.com/matlabcentral/profile/authors/14952886-erika-johtag:es.mathworks.com,2005:Question/4815812019-09-22T19:34:45Z2019-09-22T19:34:45ZHow do I fill a group of excel cells with color considering a matrix of type "Cell" that I have in matlab?Good afternoon. My problem is the following. I have a series of cell type matrices (which are of variable size according to some input data) that I am putting in an excel using the command "xlswrite" stacking them one below the other and all on the column "A", I leave the code:
fila_exc=fila_exc+NP+1; % Row where the matrix is placed in Excel
Celda_Excel=sprintf('%s%d','A',fila_exc); % The cell where the array is placed in Excel
xlswrite('testdata.xlsx',Ys_c,1,Celda_Excel); % My variable size matrix = Ys_c
The code works perfectly to put my matrices in the excel, however I am looking for each matrix placed in my excel to have a color, without having to use cell ranges, only recognizing the size of my matrix and giving color to the cells originated by said matrix.
Is there any way to get this? thanks for your helpPedro Guevarahttps://es.mathworks.com/matlabcentral/profile/authors/13162091-pedro-guevaratag:es.mathworks.com,2005:Question/4815662019-09-22T15:40:50Z2019-09-22T19:02:26Zfind finverse of cumtrapz()Hi,
I have to invert the function that calculates cumtrapz of an equation as follows:
mu = 0;
var = 1;
%x = -9:0.01:9;
syms x
f(x) = cumtrapz((2*pi*(v))^(-0.5)* exp(-((x-mu).^2)/(2*(v))))
i = finverse(f)
fplot(i)
But this gives me :
f(x) =
0
Warning: Unable to find functional inverse.
> In symengine
In sym/privBinaryOp (line 1032)
In sym/finverse (line 40)
In inverse_cdf (line 7)
i(x) =
Empty sym: 0-by-1
However the cumtrapz function does work:
mu = 0;
var = 1;
x = -9:0.01:9;
y = (2*pi*(v))^(-0.5)* exp(-((x-mu).^2)/(2*(v)));
i = cumtrapz(y);
plot(i)
what can i do to invert this functionAishwarya Radhakrishnanhttps://es.mathworks.com/matlabcentral/profile/authors/12911762-aishwarya-radhakrishnantag:es.mathworks.com,2005:Question/4815782019-09-22T18:50:34Z2019-09-22T19:02:02ZSymbolic Toolbox Integration ErrorTrialing the symbolic toolbox and attempting to run the 'Indefinite Integral of Univariate Expression' example from the int function documentation. Copy and pasting the exact code and recieve the following:
syms x
expr = -2*x/(1+x^2)^2;
F = int(expr)
--------
Error using sym/subsindex (line 855)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
-----------
Is this a settings error? Demo/trial error? The symbolic differentiation tool works just fine. Many thanks for your help!Dan Lamonehttps://es.mathworks.com/matlabcentral/profile/authors/2783252-dan-lamonetag:es.mathworks.com,2005:Question/4815582019-09-22T13:39:45Z2019-09-22T19:01:47ZHow to get image of figure with exact same size after saving on computerI would like to save image from a figure with exact same size. I have used export setup for specific size (e.g. points) of image. However, it becomes a different dimension after saving on computer memory. Is there any way to get the image of that figure with exact same size after saving it.Rafi Ahmedhttps://es.mathworks.com/matlabcentral/profile/authors/13399353-rafi-ahmedtag:es.mathworks.com,2005:Question/4815762019-09-22T17:52:07Z2019-09-22T18:58:41ZHow to add non-numerical axis values in 3D scatter plots?I am using a 3D scatter plot option. Can the x-axis values be labeled as "1:1, 2:1, 5:1, 8:1, 10:1" as peak area ratios? Currently, I added dummy numbers but the true labels should be the ratios as written. This is Matlab 2019a. Thanks.
This the syntax
scatter3(x,y,z,56, '^', 'r', 'MarkerFaceColor','r') % 56 is the marker size
Farooqhttps://es.mathworks.com/matlabcentral/profile/authors/9766874-farooqtag:es.mathworks.com,2005:Question/4639492019-05-25T04:08:12Z2019-09-22T18:52:47ZCalculate taxi fare by giving multiple inputs and single outputWrite a function called taxi_fare that computes the fare of a taxi ride. It takes two inputs: the distance in kilometers (d) and the amount of wait time in minutes (t). The fare is calculated like this:
the first km is $5
every additional km is $2
and every minute of waiting is $0.25.
Once a km is started, it counts as a whole (Hint: consider the ceil built-in function). The same rule applies to wait times. You can assume that d >0 and t >= 0 but they are not necessarily integers. The function returns the fare in dollars. For example, a 3.5-km ride with 2.25 minutes of wait costs $11.75. Note that loops and if-statements are neither necessary nor allowed.Divyang Jainhttps://es.mathworks.com/matlabcentral/profile/authors/14232458-divyang-jaintag:es.mathworks.com,2005:Question/4815742019-09-22T16:55:04Z2019-09-22T18:52:07ZHow to get the index of a value in a table?Hi everyone,
I'm new into Matlab.
I have a table T with let's say 2000 raws in one column. Values in the table are not similar.
I want to get the index of an especific value. How can I do that?
Thank youEMhttps://es.mathworks.com/matlabcentral/profile/authors/13445609-emtag:es.mathworks.com,2005:Question/4813092019-09-20T10:49:12Z2019-09-22T18:47:19Zproblem with if/else if blockHello,
I will try to be as clear as possible: I have a problem with if/else if block and maybe it comes from sampling time that I've never used before...
Here's a subsystem B:
this subsystem is inside a bigger one A
FRB and HDB are coming from outside of A, from excel spreadsheet, with sampling time 3600
Tb1 enters into B, coming from A itself, so no condition of sampling applied
Inside B I have :
when I plot TB1, it comes as it should (confronting with the plot where Tb1 is generated), but when I go into the if block:
and I plot again TB1, I have a different graph, constant as if it was "maintaining" the value for 3600s since signals HDB and FRB comes from the worksheet with this sampling time...
I know nothing about sampling time and I really don't know how to deal with that.
My excel sheet is very big and I have data every hour (3600s) that is why I put this sampling time, nowhere in my model I have put this condition but Ii think that everywhere these data will be in use, I will encounter this problem.
Thank you for any help/advice/comment
ChristineChristinehttps://es.mathworks.com/matlabcentral/profile/authors/13049384-christinetag:es.mathworks.com,2005:Question/4815562019-09-22T13:21:33Z2019-09-22T18:43:45ZWhat is the best way of fitting polynomial regression to 3 dimensional data?Hello, I have elevation measurements consist of X , Y coordinates and elevation value for each point.I want to fit polynomial regression, splines and so on ... I am trying fitnlm with modelfun but so far I did not succeed in doing so ..I am new on Matlab and machine learning so if there is any suggestions of how to do the fitting,it would be great.Thank you ..
Muhammad alaiedhttps://es.mathworks.com/matlabcentral/profile/authors/15851115-muhammad-alaiedtag:es.mathworks.com,2005:Question/4815102019-09-21T23:20:45Z2019-09-22T18:34:16ZHow to create a function that can solve and graph Euler's equationsHey guys, I'm trying to create a function that can take a differential equation and show the numerical solution via graph using Euler's Method. I have the code and it works on it's own. I just can't figure out how to get it to a function format. I tried looking at the help page but it only confused me more. I know you need to give the function inputs in order for you to get outputs, I just can't figure out where they go inside the function. Here is the code, hopefully this helps explain it.
%Section 1: Single Differential Equations.
h=0.1; % step's size
N=10; % number of steps
y(1)=1;
for n=1:N
y(n+1)= y(n)+h*(-6*y(n));
x(n+1)=n*h;
end
plot(x,y); %plots the first soltuion
hold on
h1=0.001; % step's size
N1=1000; % number of steps
y1(1)=1;
for n1=1:N1
y1(n1+1)= y1(n1)+h1*(-6*y1(n1)); %-6y1 is the differential equation, dy/dx = -6y. I had to use y1 because y is already used.
x1(n1+1)=n1*h1;
end
plot(x1,y1); % plots the second numerical solution
hold on
x3=0:0.001:1;
y3=exp(-6.*x3); %This is the solution to dy/dx = -6y
plot(x3,y3); % plots the exact solution to this differential equation
legend('h=0.1','h=0.001','Exact');
Caleb Cantrellhttps://es.mathworks.com/matlabcentral/profile/authors/13324837-caleb-cantrelltag:es.mathworks.com,2005:Question/4815752019-09-22T17:46:02Z2019-09-22T18:33:22ZWhy won't this plot?I'm new to Matlab and I'm trying to plot the velocity related to the function for a damped harmonic oscillator. I have been able to plot the function itself, but when I try to plot the velocity of said function, I receive this error:
Error using plot
Vectors must be the same length.
Error in damped_oscillator (line 102)
plot(t,v);
I'm not sure how to solve this problem. I've linked the original code. Any help is much appreciated!Derek Gabaldonhttps://es.mathworks.com/matlabcentral/profile/authors/16035797-derek-gabaldontag:es.mathworks.com,2005:Question/4806752019-09-16T20:28:23Z2019-09-22T18:19:20Zhow to write a program which controls the timing of green light according to the density on the lane if density is more then green light time is more and vice-versa on matlabdigital image processing by using smart phone camera to control traffic light monitoring system by providing time for a particular lane on the basis of density in that lane.Peeyush Raghavhttps://es.mathworks.com/matlabcentral/profile/authors/16226554-peeyush-raghavtag:es.mathworks.com,2005:Question/4815262019-09-22T04:22:25Z2019-09-22T18:15:37Z"Error using input The first argument to INPUT must be a character vector." I keep getting error from Matlab when used this code and it refere that the error in "i = input(t);", I attached my code, can anyoone helping me
start_time = 0;
end_time = 10;
dt = 0.005;
times = start_time:dt:end_time;
N = numel(times);
x = [0; 0; 10];
xdot = zeros(3, 1);
theta = zeros(3, 1);
deviation = 100;
thetadot = deg2rad(2 * deviation * rand(3, 1) - deviation);
for t = times
i = input(t);
omega = thetadot2omega(thetadot, theta);
a = acceleration(i, theta, xdot, m, g, k, kd);
omegadot = angular_acceleration(i, omega, I, L, b, k);
omega = omega + dt * omegadot;
thetadot = omega2thetadot(omega, theta);
theta = theta + dt * thetadot;
xdot = xdot + dt * a;
x = x + dt * xdot;
end
muhammad farttooshttps://es.mathworks.com/matlabcentral/profile/authors/4279675-muhammad-farttoostag:es.mathworks.com,2005:Question/4048502018-06-09T09:55:23Z2019-09-22T18:15:26ZI want to get the image I got in a function in another functionthis is the function I used to get the image
function selectImage_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.jpg';'*.bmp';'*.png''*.jpeg'},'File Selector');
handles.myImage = strcat(pathname, filename);
axes(handles.imageAxes2);
imshow(handles.myImage)
% save the updated handles object
clear axes scale
axis off
guidata(hObject,handles);
and I'm trying to use the same image in another function
function classifyImage_Callback(hObject, eventdata, handles)
net = alexnet;
image = handles.myImage;
image = imresize(image,[227 227]);
label = classify(net,image);
set(handles.imageType, 'String' , label)
<</matlabcentral/answers/uploaded_files/120768/Untitled.png>>
Mohamed Amine Habchhttps://es.mathworks.com/matlabcentral/profile/authors/12613068-mohamed-amine-habchtag:es.mathworks.com,2005:Question/4815542019-09-22T12:53:24Z2019-09-22T18:15:11Zpacking function for the file exchangeHi,
I updated a function of mine I created for the file exchange : Any 3D rotation
The main function -rotate_3D- is well included in the package when I unzip it, but it does not appear in the functions tab as you can see.
Any idea where it could come from ? Do I miss some publishing things ?
Thanks.
NicolasNicolas Douillethttps://es.mathworks.com/matlabcentral/profile/authors/8668631-nicolas-douillettag:es.mathworks.com,2005:Question/4815242019-09-22T04:06:41Z2019-09-22T18:12:55ZCan you help me please !I have 1 code vibration.
function main
d1=1;
v=10;
t_end=3;
t=0:0.01:t_end;
y0=[0;0;0;0];
[t,y]=ode45(@daodong,t,y0);
hold on;grid on;
plot(t,y(:,1))
end
function yp = daodong(t,y)
c=10;
vt=10;
k1=84.24;
m1=5.265;
I1=0.1594;
a=0.174;
yp = zeros(4,1);
yp(1) = y(2);
yp(2) = ((-(c*(y(2)-0.05*pi*vt*(sin(4*pi*vt*t))-(a*y(4)/4))+k1*(y(1)-(0.05*(sin(2*pi*vt*t))^2)-(a*y(3)/4))))/m1);
yp(3) = y(4);
yp(4) = ((-(a*c*(y(2)-0.05*pi*vt*(sin(4*pi*vt*t))-(a*y(4)/4))+a*k1*(y(1)-(0.05*(sin(2*pi*vt*t))^2)-(a*y(3)/4))))/(2*I1));
end
please help me determine acceleration at t=0 and t=t_end.
Johnny Vendettahttps://es.mathworks.com/matlabcentral/profile/authors/16105311-johnny-vendettatag:es.mathworks.com,2005:Question/4776012019-08-26T12:07:55Z2019-09-22T18:07:55Zisolate separate portions of a ASCII/TEXT FILE which have results for different time stampsi have an ascii file which can be read as text file in matlab
this file contains a number of columns (say 10 or 11) with different names(headers given in the file.
these columns are produced after different time intervals.
so basically, i have a different set of results in different separate sections of the file
What i WANT?? : I want to write these sections into separate files and read each of these columns in order to plot graphs etc.
plz help me guys
thanks in advanceshadman khanhttps://es.mathworks.com/matlabcentral/profile/authors/2725408-shadman-khantag:es.mathworks.com,2005:Question/4815612019-09-22T14:46:16Z2019-09-22T17:53:02ZHelp with intersection dicom and stl volumeHello
I've a dicom image containing 'in-vivo' data of the blood flow velocity in the main pulmunary artery(MPA) and a file stl containing a 3d solid of the MPA branching in the LPA and RPA. I ve to Intersect the Dicom image with the solid in a way that the section of the MPA coincides with the one represented in the Dicom. I've spotted the plane in where the dicom image was taken using the dicominfo command , ehich gave me it's point and normal vector from which I've written the plane equation. Moreover I've plotted the stl file using the stlread function and patch function . Now how can I superimpose the two fgures (I don t know neither how to adjust the dicom image to the newfound plane).
PS
Since the plane is not the xy i can't use the imrotate function
Thanks a lot guys!Lorenzo Peruginohttps://es.mathworks.com/matlabcentral/profile/authors/12383885-lorenzo-peruginotag:es.mathworks.com,2005:Question/4815672019-09-22T15:52:04Z2019-09-22T17:45:25ZI obtain different test success than predicted from SVM training on similar datasets.I used the quadratic SVM or the Ensemble to train a classifier using Matlab's APP. To train, I used a 250 x 15 dataset and used the default setup for validation etc... (Case_Num_Train)
The Ensemble gave me a 76.3% accuracy on the test set it extracted from the training data.
I then produce a smaller (124) set of slightly different test cases using the same technique I previously used to produce the training set (Case_Num_Real). Using the "export compact model" tool, I obtained a Trained model that can run in a script (Test_ANN). This script feeds the test data into the trained model and compares the prediction with the real case.
This gave 38 errors out of 124 test cases. This is ~30% error. It is close but something is wrong as repeating the training gives a fairly consistent 76%.
No obvious difference is seen when looking at the data from the training and test sets.
The problem worsen when I used a larger training set of 2500 cases. There a quadratic SVM gives a training accuracy of 94.6% but the test with 250 cases produces 102 errors or 40%. Not good enough!
I considered overfitting and incrementall reduced the training set to the 250 presented above. While the trained accuracy and the test accuracy do converge with smaller set, it is mostly at the cost of degraded precision.
I cannot believe that this is the best we can achieve. What is wrong?Marco Tremblayhttps://es.mathworks.com/matlabcentral/profile/authors/11730268-marco-tremblay