https://kr.mathworks.com/matlabcentral/answers/questionsMATLAB Answers — 새 질문2020-02-20T04:54:00Ztag:kr.mathworks.com,2005:Question/3062342016-10-07T13:49:27Z2020-02-20T04:54:00ZCreate and save imfreehand() positions until the user clicks a button to finishHi,
I want an image to open and the user to draw ROI with imfreehand() until they are finished - with the co-ordinates saved into structured array - - the following code does it for 3 regions of interest - - but how can i do this until the user is finished? Would be good to have an undo button too - which not only deletes the region of interest but also deletes xy co-ordinates in the array. Thanks!!
img = imread('myfig.jpg')
imshow(img)
i = 1;
for i = 1:3
hFH(i) = imfreehand();
xy{i} = hFH(i).getPosition;
endcgeneshttps://kr.mathworks.com/matlabcentral/profile/authors/8742345-cgenestag:kr.mathworks.com,2005:Question/5065342020-02-20T04:35:19Z2020-02-20T04:49:36ZMultiple specific elements in an arrayI have a matrix [a b c d e f g]. I want to sum [2*(a + b) + 3*(c+d) +4*(e+f)]. How do i go about doing this ?
Zakir Mahmoodhttps://kr.mathworks.com/matlabcentral/profile/authors/11110116-zakir-mahmoodtag:kr.mathworks.com,2005:Question/5065282020-02-20T04:04:15Z2020-02-20T04:46:32ZImplementing Gauss Elimination by pivoting with MatlabHi, I am receiving the following error for the code trying to use Gauss elimination by pivoting. I am stuck on what I am doing incorrectly.
ERROR:
'sub' requires Fixed-Point Designer.
Error in Gauss (line 1)
'sub' requires Fixed-Point Designer.
Error in Gauss (line 1)
sub Gauss(a,b,n,x,tol,r)
CODE:
sub Gauss(a,b,n,x,tol,r)
dimension s(n)
er=0;
for i=1,n
s(i)=abs(a(i,1));
for j=2,n
if abs(a(i,j))>s(i)
s(i)=abs(a(i,j));
end
end
end
call Eliminate(a,s,n,b,tol,r)
if er~= -1
call Substitue(a,n,b,x)
end
exit
sub Eliminate(a,s,n,b,tol,er)
for k=1, n-1
call Pivot(a,b,s,n,k)
if abs(a(k,k)/s(k))<tol
er=-1;
end
end
for i=k+1,n
factor=a(i,k)/a(k,k)
for j=k+1,n
a(i,j)=a(i,j)-factor*a(k,j);
end
b(i)=b(i)-factor*b(k);
end
if abs(a(n,n)/s(n))<tol
er=-1;
end
exit
sub Pivot(a,b,s,n,k)
p=k;
big=abs(a(k,k)/s(k))
for ii=k+1,n
dummy=abs(a(ii,k)/s(ii))
if dummy>big
big=dummy;
p=ii;
end
end
if p~=k
for jj=k,n
dummy=a(p,jj);
a(p,jj)=a(k,jj);
a(k,jj)=dummy;
end
dummy=b(p);
b(k)=dummy;
dummy=s(p);
s(p)=s(k);
s(k)=dummy;
end
exit
sub Substitiute(a,n,b,x)
x(n)=b(n)/(a(n,n))
for i=n-1,1,-1
sum=0;
for j=i+1,n
sum=sum+a(i,j)*x(j);
end
x(n)=(b(n)-sum)/a(n,n);
end
exitWilliam Donovanhttps://kr.mathworks.com/matlabcentral/profile/authors/15808098-william-donovantag:kr.mathworks.com,2005:Question/5065362020-02-20T04:46:23Z2020-02-20T04:46:23ZDeleting Cells in MatrixI have a Matrix 32x5
Looking at every row one at a time.
Am I able to delete all cells that are 3 greater or 3 less than the other cells in that row and then add a zero to the bottom of the column of the deleted cell to keep the matrix complete?
Thankssam van Bohemenhttps://kr.mathworks.com/matlabcentral/profile/authors/14056976-sam-van-bohementag:kr.mathworks.com,2005:Question/5060072020-02-17T16:53:42Z2020-02-20T04:42:28Zmy datatip disappears in app GUI when i add another y axisI have one xaxis and two yaxis,
namely yaxis left and yaxis right
the datatip disappears when I add the yaxis right,
Is there a solution for this?Prajwal Venkateshhttps://kr.mathworks.com/matlabcentral/profile/authors/13333755-prajwal-venkateshtag:kr.mathworks.com,2005:Question/5065302020-02-20T04:27:24Z2020-02-20T04:41:38Zwriting in excel in loop in matlabI need to write the excel file in for loop for every iteratio i need write data in A1,A2,A3 like that, help me out
I tried write in different sheet, but i need to write in same sheet but in next rows, it should not over write the previous rowPRAVIN Mhttps://kr.mathworks.com/matlabcentral/profile/authors/7624080-pravin-mtag:kr.mathworks.com,2005:Question/5065352020-02-20T04:36:44Z2020-02-20T04:36:44ZSymbolic Toolbox Problem mupadmexMy Matlab 2018b, symbolic toolbox does not work. It breaks at syms command. OS X is Catalina.
Symbolic Math Toolbox Version 8.2 (R2018b)
>> syms 't'
Error using mupadmex
Error in MuPAD command: .
Error in sym>tomupad (line 1230)
S = mupadmex(numeric2cellstr(x));
Error in sym (line 214)
S.s = tomupad(x);
Error in syms (line 205)
toDefine = sym(zeros(1, 0));
Kostas Daniilidishttps://kr.mathworks.com/matlabcentral/profile/authors/1637893-kostas-daniilidistag:kr.mathworks.com,2005:Question/5065332020-02-20T04:34:48Z2020-02-20T04:34:48ZHow to obtain Velocity?I am trying to obtain velocity from a depth broad jump. I do have acceleration but I don't know why I cannot get velocity. How can I obtain velocity? Here is my code:
cd('C:\Users\cubes\OneDrive\Documents\pilot testing\Matt\Session 1\Force data')
z=xlsread('base_depth1.xlsx','Y9543:Y10562');
sf = 1000;
%low pass cut-off
cf = 50/(sf/2);
%b,a = filter coefficients
[b,a] = butter(4,cf);
%application of Filter
F_resultant_smoothed = filtfilt(b,a,abs(z));
%number of samples (cells) within the data
Nsamps = length(F_resultant_smoothed);
%T is Time, we use frequency and samples to obtain Time
t = (1/sf)*(1:Nsamps);
%Plot(x,y) for smoothed data or plot (x1,y1,x2,y2) for smoothed and non-smoothed data
plot(t,F_resultant_smoothed);
xlabel('Time(s)');
ylabel('vGRF(n)')
%gravity
g = 9.8;
%mass of the subject while standing
mass = F_resultant_smoothed (1)/g;
%acceleration from newtons second law
acceleration = (1/mass)*(F_resultant_smoothed-mass*g);Nicholas Cubilloshttps://kr.mathworks.com/matlabcentral/profile/authors/14714054-nicholas-cubillostag:kr.mathworks.com,2005:Question/5065322020-02-20T04:28:55Z2020-02-20T04:28:55ZRank the Stuff in the order of Rating, expense, and size.stuff = {'chair','tree','book',table','pen'};
rating = {'4.6',4.5','3.4','5.6','2.3'};
expenses = {'1200','234','2345','2233','4455'};
size ={'4','3','7','8','9'};
how should I use the rank functionShashi Adhikarihttps://kr.mathworks.com/matlabcentral/profile/authors/17306150-shashi-adhikaritag:kr.mathworks.com,2005:Question/5065312020-02-20T04:28:41Z2020-02-20T04:28:41ZNumerical simulation of population growthI am trying to numerically simulate the population growth model dn/dt=rn(n/u-1)(1-n/k) If u=1000 and k = 2000, plot solutions for 5 different values of N(0) < 3000. I know how to plot I am just not sure how I am supposed to go about numerically simulating the model.Clementine Furberhttps://kr.mathworks.com/matlabcentral/profile/authors/14549351-clementine-furbertag:kr.mathworks.com,2005:Question/5064482020-02-19T17:17:40Z2020-02-20T04:25:43ZRemoving Short Runs from Binary DataI have a large string of binary data of the form:
A = [0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0]
Within the data, if I have a group of 0s with an occasional 1, I want to convert that 1 to a zero. Similarly for a group of 1s with an occasional 0.
As a rule, I want to reset runs of 1s or 0s that are shorter than 3 consecutive values in length to the value of the surrounding elements.
So 0,0,0,1,0,0,0 would become 0,0,0,0,0,0,0
I'd also like to convert something like 1,1,1,0,0,1,0,1,1 to all 1s.
Any suggestions on how to do this? Thanks in advance.Jim McIntyrehttps://kr.mathworks.com/matlabcentral/profile/authors/14896031-jim-mcintyretag:kr.mathworks.com,2005:Question/5065182020-02-20T02:25:06Z2020-02-20T04:24:44ZHow to return an individual matrix from a function that uses multiple?I have a nested parent function that operates on multiple matrices using other functions. I then want to return individual matrixes to others. Ive listed toy code below as a general example of what im trying to do:
% id like to return these matrices in a wat so that i could assign them elsewhere like:
% g = fun(d)
function fun1 = fun(a, b,c,n)
for i = 1:1:lentgth (n)
d(i) = add(a(i),b(i));
e(i) = subtract(a(i),c(i));
f(i) = multiply(b(i),c(i));
end
endLakerpurp24https://kr.mathworks.com/matlabcentral/profile/authors/14665319-lakerpurp24tag:kr.mathworks.com,2005:Question/5061342020-02-18T09:49:41Z2020-02-20T04:18:45ZHow do i find the intersection between two torus ?I have 2 torus in three-dimensional space, and i need to find the intersection between them
R=9; % outer radius of torus
r=3; % inner tube radius
th=linspace(0,2*pi,36); % e.g. 36 partitions along perimeter of the tube
phi=linspace(0,2*pi,18); % e.g. 18 partitions along azimuth of torus
% we convert our vectors phi and th to [n x n] matrices with meshgrid command:
[Phi,Th]=meshgrid(phi,th);
% now we generate n x n matrices for x,y,z according to eqn of torus
x1= (R+r.*cos(Th)).*cos(Phi) +9;
y1= r.*sin(Th) ;
z1= (R+r.*cos(Th)).*sin(Phi);
daspect([1 1 1]) % preserves the shape of torus
colormap('jet') % change color appearance
hold on
x2= ((R+r.*cos(Th)).*cos(Phi))*cos(2*pi/3) - (r.*sin(Th))*sin(2*pi/3) - 4.5;
y2= ((R+r.*cos(Th)).*cos(Phi))*sin(2*pi/3) + (r.*sin(Th))*cos(2*pi/3) + 9*sin(pi/3);
z2= (R+r.*cos(Th)).*sin(Phi);
surf(x1,y1,z1); % plot surface
surf(x2,y2,z2);
daspect([1 1 1]) % preserves the shape of torus
colormap('jet') % change color appearance
title('Torus')
xlabel('X');ylabel('Y');zlabel('Z');
Duc Lehttps://kr.mathworks.com/matlabcentral/profile/authors/12648835-duc-letag:kr.mathworks.com,2005:Question/5065292020-02-20T04:08:15Z2020-02-20T04:08:15ZHow do I process this image to look like the original?Hi all, I loaded this image from the two matrices of image data 'fitheight' and 'vel' and was wondering if there were any functions I could use to help get the loaded image looking like the original?
Loaded image:Original image:
My code:James Adamshttps://kr.mathworks.com/matlabcentral/profile/authors/17578827-james-adamstag:kr.mathworks.com,2005:Question/5065262020-02-20T03:56:55Z2020-02-20T04:07:28ZIs there a function where the inputs are indices and the outputs are vectors with a value of 1 of that index and the remainder?I am finding a function (named func, here).
If I type the following code
y = func(10, [3, 5, 1]);
then I get the following result
y = [1; 0; 1; 0; 1; 0; 0; 0; 0; 0];
The vector y is a vector with size of 10 by 1, in which the third, fifth, and first elements are one, but the rest are all zero.
Actually, I am using now the following code:
a = [3, 5, 1];
y = zeros(10,1);
y(a) = 1;
I want to use an internal function!!Dannyhttps://kr.mathworks.com/matlabcentral/profile/authors/9629617-dannytag:kr.mathworks.com,2005:Question/5056562020-02-15T15:51:25Z2020-02-20T04:07:23ZPlot 3D figure from a pcolor figureHello,
I have generated a figure by using "pcolor" to see the propagation of laser into plasma (as shown in below figure). The laser is specified by color such as read, blue,... The green color shows the plasma
But the case is I want to plot a 3D figure from this "pcolor" figure to see the real behaviour of laser inside plasma .
Therefore, I wonder is there anyone having any idea on that?
Thank you very much.dang khoa tranhttps://kr.mathworks.com/matlabcentral/profile/authors/13502707-dang-khoa-trantag:kr.mathworks.com,2005:Question/5065222020-02-20T02:57:52Z2020-02-20T04:03:46ZWhat exactly does char mean?>> answer = input('Enter YES or NO:\n','s');
fprintf('%c\n',answer)
Enter YES or NO:
YES
Y
E
S
>> answer = input('Enter YES or NO:\n','s');
fprintf('%s\n',answer)
Enter YES or NO:
YES
YES
>> E=char(i,answer)
E =
2×13 char array
'dsfdsfdsfdsfd'
'YES '
As you may notice, the first command suggests that char prints out the word character by character; however, the third command suggests that the char function simply puts out each string. Since both original data before conversion are strings, how is the result so different?Changyu Liuhttps://kr.mathworks.com/matlabcentral/profile/authors/17233012-changyu-liutag:kr.mathworks.com,2005:Question/5065272020-02-20T03:57:39Z2020-02-20T03:57:39ZHow to group individual plotted lines into one legend itemI have the following contour plot from this code. I'd like to group some of the lines I've made into one legend item. Alternatively, how can I plot in one line of code 3 line segments? I know there's an efficient way to do what I'm doing here...
Any help is appreciated.
f = @(x1, x2) 5*(x1).^2 + 7*(x2).^2 - 5*(x1) - 10*(x1).*(x2) + (x2) ;
%paths taken by each method in array for easy reference
%SD,FR,DFP,FBGS,N
SD = [5,2;3.8375,2.9765;2.3910,1.2546;2.0951,1.5032];
FR = [3.8375,2.9765;1.5,1];
DFP = [3.8375,2.9765;1.5185,0.9869;1.5320,1.0050;1.5414,1.0117];
BFGS = [3.8375,2.9765;2.4373,1.2832;2.1198,1.5279;1.7444,1.0738];
P = [5,2;2.1382,1.6729;1.5,1];
N = [5,2;1.5,1];
fcontour(f,[-2 6 -1 4],'LevelList',[-3 0 5 10 20 30 50 100]);
hold on
plot(1.5,1,'o') %optimal point
plot([SD(1,1),SD(2,1)],[SD(1,2),SD(2,2)]) %group 1
plot([SD(2,1),SD(3,1)],[SD(2,2),SD(3,2)]) %group 1
plot([SD(3,1),SD(4,1)],[SD(3,2),SD(4,2)]) %group 1
plot([FR(1,1),FR(2,1)],[FR(1,2),FR(2,2)]) %group 2
plot([DFP(1,1),DFP(2,1)],[DFP(1,2),DFP(2,2)]) %group 3
plot([DFP(2,1),DFP(3,1)],[DFP(2,2),DFP(3,2)]) %group 3
plot([DFP(3,1),DFP(4,1)],[DFP(3,2),DFP(4,2)]) %group 3
plot([BFGS(1,1),BFGS(2,1)],[BFGS(1,2),BFGS(2,2)]) %group 4
plot([BFGS(2,1),BFGS(3,1)],[BFGS(2,2),BFGS(3,2)]) %group 4
plot([BFGS(3,1),BFGS(4,1)],[BFGS(3,2),BFGS(4,2)]) %group 4
plot([P(1,1),P(2,1)],[P(1,2),P(2,2)]) %gruop 5
plot([P(2,1),P(3,1)],[P(2,2),P(3,2)]) %group 5
plot([N(1,1),N(2,1)],[N(1,2),N(2,2)]) %group 5
legend('F(x1,x2)','optimal','SD','FR','DFP','BFGS','P','N')
title('Contour Plot of F(x1,x2)')
xlabel('x1')
ylabel('x2')Sylvain Cornelushttps://kr.mathworks.com/matlabcentral/profile/authors/7655618-sylvain-cornelustag:kr.mathworks.com,2005:Question/5065252020-02-20T03:52:50Z2020-02-20T03:53:59ZI need to plot a trajectory, of a point on circumference of a circle moving around its centre and centre is moving along its x-axis.% please help i dont undrestandChetlal Mahtohttps://kr.mathworks.com/matlabcentral/profile/authors/17467156-chetlal-mahtotag:kr.mathworks.com,2005:Question/4756372019-08-10T03:40:14Z2020-02-20T03:53:24ZMatlab cannot identify the mex function I am trying to run the symmetry dectection algorithm proposed in the paper "Detecting Symmetry and Symmetric Constellations of Features".
http://www.nada.kth.se/~gareth/homepage/local_site/code.htm
One weird thing happend is that I can perfectly run the code without error in my laptop. But when I copy those file into my desktop computer. The mex function cannot be found. It shows the error message:
Undefined function or variable 'histc_weighted_mex'.
Error in histc_weighted (line 67)
hist = histc_weighted_mex(x,weights,edges);
Error in linear_hough (line 30)
Hough_im = reshape(histc_weighted(ind_hs,weights,[1:prod(size(Hough_im))]), size(Hough_im));
Error in symmetry (line 82)
[Hough_im, max_r, max_ang, r, sym_strength] = linear_hough(im,sym_x,sym_y,ang,phase_weight);
I have no idea why this error occur? Can anyone help me?
Both two computer are using MATLAB R2018bKwun Yu Wuhttps://kr.mathworks.com/matlabcentral/profile/authors/14636051-kwun-yu-wutag:kr.mathworks.com,2005:Question/5065242020-02-20T03:50:33Z2020-02-20T03:50:33ZLine Search Algorithm helpThis part is just the background to the algorithms I am working on:
Here is the code I currently have but I'm not sure what to do to get anything to work:
function [alpha] = linesearch(nsteps)
syms x
f = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
grad = [-400*(x(2)-x(1)^2)*x(1)-2*(1-x(1)); 200*(x(2)-x(1)^2)];
gradTwo = [800*x(1)+2, -400*x(1); -400*x(2), 200];
alpha(0) = 0;
alpha(1) = 1;
c1 = 10^-4;
c2 = 0.9;
for i = 1:nsteps
if (f(alpha(i)) > f(0)+c1*grad(0)||(f(alpha(i)) > f(alpha(i-1))))
alpha = lszoom(alpha(i-1), alpha(i));
return;
end
if abs(grad(alpha(i))) <= abs(c2*grad(0))
alpha = alpha(i);
return;
end
if grad(alpha(i)) >= 0
alpha = lszoom(alpha(i), alpha(i-1));
return;
end
alpha(i+1) = 2*alpha;
end
Error('step size alpha not found within 10 iterations')
end
function [alpha] = lszoom(alphalo, alphahigh)
syms x
f = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
grad = [-400*(x(2)-x(1)^2)*x(1)-2*(1-x(1)); 200*(x(2)-x(1)^2)];
gradTwo = [800*x(1)+2, -400*x(1); -400*x(2), 200];
alpha(0) = 0;
alpha(1) = 1;
c1 = 10^-4;
c2 = 0.9;
nsteps = 50;
for i = 1:nsteps
alpham = (alphalo + alphahigh) / 2;
if (f(alpham) > alpha(0)+c1*alpham*grad(0)||f(alpham)>f(alphalo))
alphahigh = alpham;
else
if abs(grad(alpham)) <= c2*abs(grad(0))
alpha = alpham;
return;
end
if grad(alpham)*(alphahigh-alphalo) >= 0
alphahigh = alphalo;
end
alphalo = alpham;
end
end
Error('step length alpha not found within 50 iterations')
end
Both algorithms give me the error:
"Index exceeds the number of array elements (1)
Error in sym/subsref (line 900)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in lszoom (line 4)
grad = [-400*(x(2)-x(1)^2)*x(1)-2*(1-x(1)); 200*(x(2)-x(1)^2)];"Sarah Johnsonhttps://kr.mathworks.com/matlabcentral/profile/authors/16227697-sarah-johnsontag:kr.mathworks.com,2005:Question/5061152020-02-18T07:58:37Z2020-02-20T03:49:50ZCollector for array formed of replicated subararraysI'm trying to use the Collector object with an array formed of replicated subarrays, but I keep receiving messages of 'not enough inputs'; that is:
collector = phased.Collector('Sensor',array,'OperatingFrequency',fc);
rxData = collector(sig,targetAngle);
'Not enough input arguments. Expected 3, got 2.'
Could someone please help me with that? What other inputs are necessary?
Another question regarding either the Collector or Radiator objects, do they take into account the antenna gain at the designated angle of the specified sensor when simulating the transmitting/received signal?
Thanks in advance.Katiahttps://kr.mathworks.com/matlabcentral/profile/authors/1921416-katiatag:kr.mathworks.com,2005:Question/5063462020-02-19T09:56:52Z2020-02-20T03:44:02ZHow to assign timetable as cell type?Hello,
Can anybody tell me how can I assign a timetable as cell type, and store it inside a table as shown in the image below.
Sagar Duttahttps://kr.mathworks.com/matlabcentral/profile/authors/6850557-sagar-duttatag:kr.mathworks.com,2005:Question/5065232020-02-20T03:11:51Z2020-02-20T03:43:05ZHow to Read and plot CSV file and delete infinity values from CSV file Hi
I want to read csv file and later plot it by using some formula.
I used csvread, but it doesn’t work as the file contains text (column title) and infinity values which MATLAB read as âˆž.
I tried with readtable it can read (c=readtable('sensor.csv');. But again I can’t delete infinity values from the file. When I try with c(isnan(c))=0; or c(~any(isinf(c))) = 0; it always give error
“Undefined function 'isinf' or ‘isnan’ for input arguments of type 'table'”
Can anyone help how to read large csv file (xlsread doesn’t work, file size>1gb) and delete the infinity values which MATLAB read âˆž.
Small section of large file is attached sensor.csvLeehttps://kr.mathworks.com/matlabcentral/profile/authors/15263967-leetag:kr.mathworks.com,2005:Question/5042812020-02-07T20:35:24Z2020-02-20T03:39:44Zis there any way to use a bmp file with PRM to find path planning routeIs there a way to input a .bmp file with obstacles defined into the robotics.PRM functions to define path planning ?
I can't seem to create the axis configuration I want and the non-circular obstacles using the the robotics.OccupancyGrid function and have to save a figure as a .bmp file instead. But I can't seem to get anything sensible when I pass it through the PRM path planning function.William Campbellhttps://kr.mathworks.com/matlabcentral/profile/authors/10967941-william-campbelltag:kr.mathworks.com,2005:Question/5065072020-02-20T00:22:09Z2020-02-20T03:39:05ZAppending a row vector into a matrix based on given conditionsIn my current code I have created a 604x1 matrix called b where I subtracted -60 and -550, the smaller of the values would then call a row in a larger matrix, 604x3, called data and append the row into one of the two empty matrices I have set up plane550 and plane60 depending on whichever value was greater than the other. Could someone guide me as to how to fix the problem in my code given below as running it gives me a single matrix that is equal to data in size.
xzplane60 = [];
xzplane550 = [];
for ii = 1:size(equakemat,1)
if abs(b(ii)-60) > abs(b(ii)-550)
xzplane550 = [xzplane550; equakemat(ii,:)];
else
xzplane60 = [xzplane60; equakemat(ii,:)];
end
end
Michael Wuhttps://kr.mathworks.com/matlabcentral/profile/authors/16147941-michael-wutag:kr.mathworks.com,2005:Question/1315482014-05-28T22:10:57Z2020-02-20T03:38:54ZWhy did my LOAD stop working?I have code that makes the following call:
[net,~] = LoadDailyNet(option).
The function performs the load call:
load('WCF\Networks\NorthDailyNet', 'net').
The call worked OK until, suddenly, one day I get the following message:
Warning: Could not determine the fields for class network by calling the constructor with no input arguments. The object net has been converted to a structure. To eliminate the conversion create an object of class network before calling LOAD.
I suspect the Administrator may have changed something in the configuration. Before I change my code I want to make sure that this cannot be resolved globally. Other Developers may have done the same thing I did. Harold Kidderhttps://kr.mathworks.com/matlabcentral/profile/authors/2549356-harold-kiddertag:kr.mathworks.com,2005:Question/5065092020-02-20T00:42:40Z2020-02-20T03:36:43ZHow to simply the code to reduce elapsed timeHello,
I have a script that is running (a for loop) : to get path of audio, saving the audio, play the audio(that is a function). However, I realized that using tic and toc the elapsed time is about 3 seconds for a trial to run. I am thinking that it is the play audio section that slow down the program. I am wondering is there a way to keep what I have but reduce the elapsed time? Here is the attached code:
for trial=1:block1
% Load audio file into matlab
filename = fnames(trial);
filepath = fullfile(PracticeSounds,filename);
C=clock;
saveas = fullfile(ResultsFolder,strcat([date,num2str(C(4)),'h',num2str(C(5)),'m',num2str(C(6)),'s'],char(filename)));
playRecord(char(filepath),char(saveas));
end
And the playrecord function:
function[]=playRecord(pathToSoundFile, pathToResultsFile)
pause_after_stim=1;
fs=44100;%setting the sampling frequency of the record
length= playSoundSync(pathToSoundFile);
GetVoice=audiorecorder(fs,16,1,1);
recordblocking(GetVoice,length+pause_after_stim);
getRecording=getaudiodata(GetVoice);
recording = getRecording;
audiowrite(pathToResultsFile,recording,fs);
end
function[audioLength]=playSoundSync(name)
[Stim,fs] = audioread(name);
sound(Stim,fs);
audioLength = length(Stim)./fs;
end
Is it possbile to reduce the elapsed time? Thankssteamricehttps://kr.mathworks.com/matlabcentral/profile/authors/8605527-steamricetag:kr.mathworks.com,2005:Question/5065212020-02-20T02:49:20Z2020-02-20T03:35:55Zhow to use the previous frame of a video in a loop without saving it
hello,
I am trying to compute the silhoutte motion image from a silhouette of video, i want to perform all the steps in a sequence with saving the silhouette and then working on it. as my application is real-time
i used this code to extract the silhouette
v = VideoReader('2.mp4');
nFrames = v.NumberOfFrames;
for f=1:nFrames
I=read(v,f);
if f==1
Background=I;
Fg=abs(I-Background);
else
Fg=abs(I-Background);
end
grayImage = rgb2gray(abs(im2double(Fg))); % Convert to gray level
thresholdLevel = graythresh(grayImage);
binaryImage = im2bw(grayImage,thresholdLevel);
% now for the silhouette motion image i have to compute
for n=1:f
if f==1
smi1=binaryImage;
else
smi1=abs(binaryImage+binaryImage(previous frame i.e (f-1));
end
end
smii=abs(smi1-bi);
my question is how do i access the previous frame within the loop, without saving itSaba Balochhttps://kr.mathworks.com/matlabcentral/profile/authors/17424304-saba-balochtag:kr.mathworks.com,2005:Question/5065172020-02-20T02:02:36Z2020-02-20T03:19:46ZI'm trying to understand your tables command bugs% Why does this happen?
A = randi([0 20],5, 5)
table(A,'RowNames',{'a' 'b' 'c' 'd' 'e'}) % doesn't work
table(A(:,1)','RowNames',{'a' 'b' 'c' 'd' 'e'},'VariableNames',{'a'}) % Doesn't work
table(A(1,:)','RowNames',{'a' 'b' 'c' 'd' 'e'},'VariableNames',{'a'}) % Works
% Who's writing this software?Stephen Wilkersonhttps://kr.mathworks.com/matlabcentral/profile/authors/9494232-stephen-wilkersontag:kr.mathworks.com,2005:Question/4118462018-07-24T08:20:06Z2020-02-20T02:53:19ZHow to create Favorites by code / Command Window?I was used to create the shortcuts in R2017b and older via code:
jUtils = com.mathworks.mlwidgets.shortcuts.ShortcutUtils;
jUtils.addShortcutToBottom(sName,sCcallback,sIcon,sCategory, 'true');
Of course it does not work to create the new "favorites", but I would like to do so.
I have found the com.mathworks.mlwidgets.favoritecommands.FavoriteCommandProperties class with get/set methods, but if I got it right, I would Need some stuff from com.mathworks.mlwidgets.favoritecommands.FavoriteCommandActions, which has not constructor.
Any ideas out there, how to create favorites and their categories by code?sfreemanhttps://kr.mathworks.com/matlabcentral/profile/authors/807112-sfreemantag:kr.mathworks.com,2005:Question/157702011-09-13T17:37:53Z2020-02-20T02:41:48ZScaling the FFT and the IFFTWhat is the correct way to scale results when taking the Fast Fourier Transform (FFT) and/or the Inverse Fast Fourier Transform (IFFT)?Rick Rossonhttps://kr.mathworks.com/matlabcentral/profile/authors/1061251-rick-rossontag:kr.mathworks.com,2005:Question/5065202020-02-20T02:39:34Z2020-02-20T02:39:34Zproblem in dumping the simulink model at high sampling frequency in TMS320f28379.hello everyone,
i hope you all doing well. I have a one question hardware modelling in simulink. IN C2000 TMS320f28379d DSP board, i am trying dump the simulink model at sampling time 1e-6 it is is not dumping,what changes i need to do for run the model.but it is running at 1e-4sampling time? some error is comming when i dump the code at 1e-6 sampling time, the error like Code replacement library must provide entries for semaphore/mutex creation.help me get this problem out.mahesh reddy pundruhttps://kr.mathworks.com/matlabcentral/profile/authors/13893116-mahesh-reddy-pundrutag:kr.mathworks.com,2005:Question/3791962018-01-26T16:36:23Z2020-02-20T02:25:35ZHow to solve integral of vector How do I use the integral function on a vector? I tried this:
fun=@(s)expm(Ae*s)*h
q=@(t)integral(fun,0,t)
Ae is a matrix and h is a vector.Louisehttps://kr.mathworks.com/matlabcentral/profile/authors/6832167-louisetag:kr.mathworks.com,2005:Question/5065042020-02-19T23:37:12Z2020-02-20T02:19:05ZHow to find where a very long code is stuck?This code is a part of coding a mutiobjective genetic algorithm, the algorithm for this code is as follows:
Initialization: Q=Ro; ND= , Ro is the initial population
Randomly select a row x of Q, and set Q=Q-{x} [here I mean remove the row x from Q], RK= , R=
while ( Q )
for each y in Q do,
if x dominates y, then remove y from Q and update Q {Q=Q-{y}}
elseif, y dominates x then update x=y; and update Q by removing y from Q, Q=Q-{y}, RK=RK R then update R= [but since they are matrices so I use RK=[RK;R]; ]
else, R= R {y} [I used R=[R;Y]; ], update Q by removing the row y from it
end(if)
end(do)
4. Take all the rows y in RK which are not dominated by x and put them in a matrix RKK
5.ND=[ND;x];
6.Q=[RKK;R];
7. If the number of rows in Q >1 then go to step 2, otherwise set ND=[ND;Q]; stop
in the code:
output=FD( x,y,Nvar,perci,Lb,Ub); is a function I wrote takes the rows/individuals x,y and returns 2 by Nvar*perci matrix named output, where the first row is the non-dominated individual and the second is the dominated one
Remark: In FD, 2 individuals/rows x,y has 3 outputs either x dominates y or y dominates x or no one dominates the other
in the first 2 cases FD returns: a matrix, 2 by Nvar*perci matrix named output, where the first row is the non-dominated individual and the second is the dominated one, in the third case it returns a matrix: output or 2 rows and Nvar*perci cols where each element in it is INF
I hope someone can help me because I am a beginner in MATLAB.
Thanks
Nind=100; %number of individuals to begin with
Nvar=1; %number of the decision variables
perci=10; %number of bits of every decision variable
Ro=crtbp(Nind,Nvar*perci); %random matrix of 0 and 1
%each element in it, is either 0 or 1
%crtbp is a function from GA toolbox
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[Fronts,ranks]=IMPARENA(Nvar,perci,Ro,Lb,Ub)
iii=1; DOM=[]; ranks=[]; Lb=-100; Ub=100;
while ~isempty(Ro)
Q=Ro; carQ=size(Q,1);
ND=[];
while carQ>1
x=Q(1,:);
Q=Q(2:end,1:end); %remove x from Q
RK=[]; R=[]; RKK=[];
while ~isempty(Q) %while Q is not empty
y=Q(1,:); %let y be the first row in Q
output=FD( x,y,Nvar,perci,Lb,Ub); %check the dominance between y and x
if norm(x- output(1,1:end))==0 %if x dom y
%remove y from Q;
Q(all(Q==repmat(y,size(Q,1),1),2),:)=[];
elseif norm(y-output(1,1:end))==0 %if y dom x
x=y;
%remove y from Q
Q(all(Q==repmat(y,size(Q,1),1),2),:)=[];
RK=[RK;R]; R=[];
else
R=[R;y];
%remove y from Q
Q(all(Q==repmat(y,size(Q,1),1),2),:)=[];
end
if ~isempty(RK)
for j=1:size(RK,1)
rr=RK(j,1:end);
output=FD(x,rr,Nvar,perci,Lb,Ub);
if norm(x-output(1,1:end))~=0 %x~=output(1,1:end)
RKK=[RKK;rr];
else
j=j+1;
end
end
end
ND=[ND;x];
QSS=[RKK;R]; %%the code gets stuck here%%%
Q=QSS;
carQ=size(Q,1);
if carQ>1
break;
end
end
end
ND=[ND;Q];
%%%%%%%%%%%%%%%%%%%%%%%%%
UND=unique(ND, 'rows', 'stable');
ND=UND;
%%%%%%%%%%%
DOM=[DOM;ND];
%%%%%%
%assigning ranks
rD=iii*ones(size(ND,1),1);
ranks=[ranks;rD];
iii=iii+1;
%%%%%%%%%%%%%%%
C=setdiff(Ro,ND,'rows');
Ro=C;
end
%%%%%%%%%END%%%%%%%%%%%%
Fronts=[DOM];
ranks;
end
Matlab tell me that the error at the line I referred to but I don't understand why it tells me:
QSS is 1x10 double, RKK 0X0 empty double and R is 2x10 double
and that Q is empty 0x10 double!
Why? and what does it mean?
EDIT: The code sometimes work and sometimes it gets stuck, so maybe there is something computational that happens
because every time crtbp generates a different random binary matrix Ro
QSS=[RKK;R]; %it points that the problem is here
Q=QSS;
And it says that RKK is empty 0 x 0 double
QSS is empty 1 x 10 double
R is 2 x 10 double and that Q is 0 x 0 empty
Q is a matrix which changes its size through the loopCantor Sethttps://kr.mathworks.com/matlabcentral/profile/authors/14440086-cantor-settag:kr.mathworks.com,2005:Question/5065082020-02-20T00:38:46Z2020-02-20T02:16:51ZWhy is this code stuck?This code is a part of coding a mutiobjective genetic algorithm, the algorithm for this code is the following:
Initialization: Q=Ro; ND= , Ro is the initial population
Randomly select a row x of Q, and set Q=Q-{x} [here I mean remove the row x from Q], RK= , R=
while ( Q )
for each y in Q do,
if x dominates y, then remove y from Q and update Q {Q=Q-{y}}
elseif, y dominates x then update x=y; and update Q by removing y from Q, Q=Q-{y}, RK=RK R then update R= [but since they are matrices so I use RK=[RK;R]; ]
else, R= R {y} [I used R=[R;Y]; ], update Q by removing the row y from it
end(if)
end(do)
4. Take all the rows y in RK which are not dominated by x and put them in a matrix RKK
5.ND=[ND;x];
6.Q=[RKK;R];
7. If the number of rows in Q >1 then go to step 2, otherwise set ND=[ND;Q]; stop
in the code:
output=FD( x,y,Nvar,perci,Lb,Ub); is a function I wrote takes the rows/individuals x,y and returns 2 by Nvar*perci matrix named output, where the first row is the non-dominated individual and the second is the dominated one
Remark: In FD, 2 individuals/rows x,y has 3 outputs either x dominates y or y dominates x or no one dominates the other
in the first 2 cases FD returns: a matrix, 2 by Nvar*perci matrix named output, where the first row is the non-dominated individual and the second is the dominated one, in the third case it returns a matrix: output or 2 rows and Nvar*perci cols where each element in it is INF
I hope someone can help me because I am a beginner in MATLAB.
Thanks
Nind=100; %number of individuals to begin with
Nvar=1; %number of the decision variables
perci=10; %number of bits of every decision variable
Ro=crtbp(Nind,Nvar*perci); %random matrix of 0 and 1
%each element in it, is either 0 or 1
%crtbp is a function from GA toolbox
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[Fronts,ranks]=IMPARENA(Nvar,perci,Ro,Lb,Ub)
iii=1; DOM=[]; ranks=[]; Lb=-100; Ub=100;
while ~isempty(Ro)
Q=Ro; carQ=size(Q,1);
ND=[];
while carQ>1
x=Q(1,:);
Q=Q(2:end,1:end); %remove x from Q
RK=[]; R=[]; RKK=[];
while ~isempty(Q) %while Q is not empty
y=Q(1,:); %let y be the first row in Q
output=FD( x,y,Nvar,perci,Lb,Ub); %check the dominance between y and x
if norm(x- output(1,1:end))==0 %if x dom y
%remove y from Q;
Q(all(Q==repmat(y,size(Q,1),1),2),:)=[];
elseif norm(y-output(1,1:end))==0 %if y dom x
x=y;
%remove y from Q
Q(all(Q==repmat(y,size(Q,1),1),2),:)=[];
RK=[RK;R]; R=[];
else
R=[R;y];
%remove y from Q
Q(all(Q==repmat(y,size(Q,1),1),2),:)=[];
end
if ~isempty(RK)
for j=1:size(RK,1)
rr=RK(j,1:end);
output=FD(x,rr,Nvar,perci,Lb,Ub);
if norm(x-output(1,1:end))~=0 %x~=output(1,1:end)
RKK=[RKK;rr];
else
j=j+1;
end
end
end
ND=[ND;x];
QSS=[RKK;R]; %%the code gets stuck here%%%
Q=QSS;
carQ=size(Q,1);
if carQ>1
break;
end
end
end
ND=[ND;Q];
%%%%%%%%%%%%%%%%%%%%%%%%%
UND=unique(ND, 'rows', 'stable');
ND=UND;
%%%%%%%%%%%
DOM=[DOM;ND];
%%%%%%
%assigning ranks
rD=iii*ones(size(ND,1),1);
ranks=[ranks;rD];
iii=iii+1;
%%%%%%%%%%%%%%%
C=setdiff(Ro,ND,'rows');
Ro=C;
end
%%%%%%%%%END%%%%%%%%%%%%
Fronts=[DOM];
ranks;
end
Matlab tell me that the error at the line I referred to but I don't understand why it tells me:
QSS is 1x10 double, RKK 0X0 empty double and R is 2x10 double
and that Q is empty 0x10 double!
Why? and what does it mean?
EDIT: The code sometimes work and sometimes it gets stuck, so maybe there is something computational that happens
because every time crtbp generates a different random binary matrix RoCantor Sethttps://kr.mathworks.com/matlabcentral/profile/authors/14440086-cantor-settag:kr.mathworks.com,2005:Question/5065152020-02-20T01:45:40Z2020-02-20T02:09:00ZDesigning IIR Butterworth filter (pass band)Hi team,
I have collected the raw data . i need to design IIR Butter filter (pass band ) can any one help me regarding this.
and we have already designed IIR Butter filter 3*6 sos in that how to increase the order insted three i need 5 order it is possible ?santhosh premhttps://kr.mathworks.com/matlabcentral/profile/authors/16231071-santhosh-premtag:kr.mathworks.com,2005:Question/5063912020-02-19T13:25:31Z2020-02-20T02:04:46ZRaspberry Pi with MPU6050 Sensor Data Visualisation (Accelerometer, Gyroscope)#!/usr/bin/python
import smbus
import math
import requests
import json
power_mgmt_1 = 0x6b
power_mgmt_2 = 0x6c
def read_byte(reg):
return bus.read_byte_data(address, reg)
def read_word(reg):
h = bus.read_byte_data(address, reg)
l = bus.read_byte_data(address, reg+1)
value = (h << 8) + l
return value
def read_word_2c(reg):
val = read_word(reg)
if (val >= 0x8000):
return -((65535 - val) + 1)
else:
return val
def dist(a,b):
return math.sqrt((a*a)+(b*b))
def get_y_rotation(x,y,z):
radians = math.atan2(x, dist(y,z))
return -math.degrees(radians)
def get_x_rotation(x,y,z):
radians = math.atan2(y, dist(x,z))
return math.degrees(radians)
bus = smbus.SMBus(1) # bus = smbus.SMBus(0) fuer Revision 1
address = 0x68 # via i2cdetect
bus.write_byte_data(address, power_mgmt_1, 0)
print "Gyrosk
op"
print "--------"
while(True):
gyroskop_xout = read_word_2c(0x43)
gyroskop_yout = read_word_2c(0x45)
gyroskop_zout = read_word_2c(0x47)
print "gyroscope_xout: ", ("%5d" % gyroskop_xout), " skaliert: ", (gyroskop_xout / 131)
print "gyroscope_yout: ", ("%5d" % gyroskop_yout), " skaliert: ", (gyroskop_yout / 131)
print "gyroscope_zout: ", ("%5d" % gyroskop_zout), " skaliert: ", (gyroskop_zout / 131)
# How to send the above sensor data to ThingSpeak ? Please Help.
Jayanth Tadikondahttps://kr.mathworks.com/matlabcentral/profile/authors/13782184-jayanth-tadikondatag:kr.mathworks.com,2005:Question/5065162020-02-20T01:57:03Z2020-02-20T01:59:02Zaverage and std deviation of user input of a number of inputs, decided by user. I'm trying to help my Fiance with her problem(I'm on her account) for her engineering programming class. I know a good bit about C++ and Java but I'm completely unaccustomed to MATLAB and so I'm not doing all that well helping her. Does anyone know how to do this? I would greatly appreciate the help, I've looked but there doesn't seem to be anything online that's the same. She has to use the mean and std deviation functions in the program as well.
Hannah Tauriellohttps://kr.mathworks.com/matlabcentral/profile/authors/17333176-hannah-tauriellotag:kr.mathworks.com,2005:Question/4520752019-03-24T20:45:32Z2020-02-20T01:54:12ZLSTM: Multi Input to Single Output Regression - Wrong Input formHello,
i'm trying to map several inputs (human biosignals and stats) to a single value (concerning the heartrate).
I'm trying to understand what form my inputs needs to be, but i feel really stuck, since my lstm works with "dummy" input- matrices, but it seems to me, that i'm still missing something completely.
layers = [ ...
sequenceInputLayer(7)
lstmLayer(numHiddenUnits_lstm,'OutputMode','sequence')
lstmLayer(numHiddenUnits_lstm,'OutputMode','sequence')
fullyConnectedLayer(1)
regressionLayer
];
maxEpochs = 15;
miniBatchSize = 1;
options = trainingOptions('adam', ...
'MaxEpochs',maxEpochs, ...
'MiniBatchSize',miniBatchSize, ...
'InitialLearnRate',0.01, ...
'GradientThreshold',1, ...
'Shuffle','never', ...
'Plots','training-progress',...
'ValidationFrequency',4, ...
'Verbose',0);
net = trainNetwork(LSTMARR3,LSTMARR_targets,layers,options);
My Input : LSTMARR3
My Output : LSTMARR_targets
Below i tried to show you how i formatted my data, so can you please help me how to feed my data to my network?
Andreas Stapfhttps://kr.mathworks.com/matlabcentral/profile/authors/14411761-andreas-stapftag:kr.mathworks.com,2005:Question/5062132020-02-18T16:30:44Z2020-02-20T01:24:42ZHow to create an object using class nameIn my function, I am getting the class name from an object to create a new one. What is the right syntax to creat the new Object ?
function newObj = createNewObject(obj)
className = class(obj);
newObj = className();
endSylvainhttps://kr.mathworks.com/matlabcentral/profile/authors/3333169-sylvaintag:kr.mathworks.com,2005:Question/5065132020-02-20T01:20:15Z2020-02-20T01:20:15ZData import to SignalBuilder
How do I import from an Excel file using a command?
thanksAkihiko Uedahttps://kr.mathworks.com/matlabcentral/profile/authors/16434440-akihiko-uedatag:kr.mathworks.com,2005:Question/4597122019-05-02T00:10:24Z2020-02-20T01:18:58ZWhat is the probability distribution used in PRM?What is the probability distribution used to sample the points in the path planner of the probabilistic roadmap algorithm? Is there any way to change this?Antonio Mendeshttps://kr.mathworks.com/matlabcentral/profile/authors/14669307-antonio-mendestag:kr.mathworks.com,2005:Question/5065122020-02-20T01:16:03Z2020-02-20T01:17:36ZHow to use perfcurve to plot ROC curves for 3 classes?I have a multiclass problem. My data needs to be classified between 3 different classes.
I know that the ROC curve considers one class against the other two at a time.
I want to know how to use the perfcurve function to generate the three ROC and also AUC curves for each case.
The classification problem was solved using neural networks.
My target matrix is in the 3x500 model where each column has a value of 1 and two 0, representing the correct class.
My resulting values are 3x500 dimension too, where each column has the propability values of the element belonging to each class.
I verified that perfcurve's arguments need to be vectors. So I used functions to identify the indices of the highest values in each column of the matrix (resulting in 1, 2 or 3, the classes of each element).
So I got a 500x1 target vector and a 500x1 predicted value vector.
I tried to use perfcurve (targets, predicts, X), where X I varied as 1, 2 and 3 (positive class). The graphics I got don't make a lot of sense. They are totally different from when I use plotroc ()
What am I doing wrong?Antonio Mendeshttps://kr.mathworks.com/matlabcentral/profile/authors/14669307-antonio-mendestag:kr.mathworks.com,2005:Question/5062892020-02-18T23:02:46Z2020-02-20T01:13:45Zsplitting up a timeseries into separate componentshi all!
I am trying to seperate chunks of a timeseries into sleep vs. wake components.
I'm having problems with two things:
1) I've figured out how to do it with one section, but I want to be able to do it with multiple sections, e.g. 200-600 seconds and 750-800 seconds.
2) I also want to take these chunks of the timeseries and then calculate the power. When I try to run my script to calculate the power, I get a ton of errors I think because sleep_c (etc) is = 1x1 double times, rather than my normal ts = 1000x1 double
thanks times a million:
I've done this:
%%%%loading
sleep_behavior = 1500:3000
sleep_c = timeseries(d_c_ts_1(sleep_behavior,1), 1500:3000,'name', 'fMRI signal')
sleep_behavior = 1500:3000
sleep_v = timeseries(d_v_ts_1(sleep_behavior,1), 1500:3000,'name', 'fMRI signal')
wake_behavior = 100:200
wake_c = timeseries(d_c_ts_1(wake_behavior,1), 100:200,'name', 'fMRI signal')
wake_behavior = 100:200
wake_v = timeseries(d_v_ts_1(wake_behavior,1), 100:200,'name', 'fMRI signal')
%% calculating power of sleep vs. wake ----- power vs. frequency
for a = 1:1
name = sleep_v
[power_sleep_v, f] = mtspectrumc(name,params) %detrended cortex young person
end
nineshttps://kr.mathworks.com/matlabcentral/profile/authors/15883041-ninestag:kr.mathworks.com,2005:Question/5065112020-02-20T01:03:37Z2020-02-20T01:03:37ZNumber of parameters in feedforward neural network.How can I show the number of parameters of a trained net?
Thanks in advance.Mustafa Sobhyhttps://kr.mathworks.com/matlabcentral/profile/authors/14171338-mustafa-sobhytag:kr.mathworks.com,2005:Question/5065102020-02-20T00:55:41Z2020-02-20T00:55:41ZHow to use transfer learning on U-net created in Matlab?Hi,
I'm interested in using a U-net that I have trained in Matlab on one set of data and then applying transfer learning on the last couple layers with another set of data (as shown in https://www.mathworks.com/help/deeplearning/gs/get-started-with-transfer-learning.html )
How would this process work with a network created using U-net layers in Matlab? Also, is the U-net layer in Matlab already pre-trained using some other set of data when it's used in the script?
Thank youHridayihttps://kr.mathworks.com/matlabcentral/profile/authors/7044219-hridayitag:kr.mathworks.com,2005:Question/5065052020-02-20T00:05:38Z2020-02-20T00:36:32ZHow do I add a for loop to do subplotsCreate a subplot with two graphs subplot(2,1,x). The top plot will be your summed sinusoids and the bottom will show all the sinusoids used to create the final sinusoid. To do this, use the for loop to create a matrix that contains three vectors, one for each of the base sinusoids. Then use one command (outside your function) to plot all three together on the bottom subplot.
My code is below but I am unsure how or where to add a for loop to execute this. My thought was to store the "x" value and then plot it.
function [xx,tt] = syn_sin(fk,xk,fs,dur,tstart)
if nargin <5, tstart=0, end
if length (xk)~= length(fk)
error ('error', 'fk~=xk');
end
t= tstart: 1/(fs):dur;
x=xk(1)* exp(2*j*pi*fk(1)*t);
for k=2:length(fk);
x=xk(k) *exp(2*j*pi*fk(k)*t) +x;
end
plot(t,x),grid on Dalton Houghton-Schafferhttps://kr.mathworks.com/matlabcentral/profile/authors/15804885-dalton-houghton-schaffertag:kr.mathworks.com,2005:Question/5064042020-02-19T14:12:29Z2020-02-20T00:28:13Zhow to upload a random excel file and read itI am working on an assignment in which i want to develope a stand alone app (GUI) of curve fitting.
in which i need to get data input from a random excel file,and read that file to make a graph.
under 'upload file'i wrote this fuction
function pushbutton2_Callback(hObject, eventdata, handles)
a= uigetfile({'*.xlsx'},'select the excel file');
b=xlsread('a);
under 'calculate' i wrote this fuction
function pushbutton1_Callback(hObject, eventdata, handles)
x=dataset(:,1);
y=dataset(:,2);
p=polyfit(x,y,5);
xp=0:0.1:0.5;
yp=polyval(p,xp);
plot(x,y,'--',xp,yp);
grid;
-- its not working,i want matlab to open a 'select window' so a user can upload a rondom excel file(which contain data),and when the user click the 'calculate button' it will fit the curve.
ubaidullah abbashttps://kr.mathworks.com/matlabcentral/profile/authors/17581018-ubaidullah-abbastag:kr.mathworks.com,2005:Question/5064592020-02-19T18:13:35Z2020-02-20T00:18:31ZHow to solve a simple Matrix equation?Hello,
I have a small problem. I want to solve the multiplication of a given matrix.
For Example:
A = [-1,0,0,1;1,-1,0,0;0,1,-1,0;0,0,1,-1];
x = sym('x', [4,1]);
x(1,1)=1;
solve(A*x==[0;0;0;0])
Because I am a beginner at Matlab, I really don't know what im doing wrong. In this Example x should be equal to ones.
The goal is, to use it for a big matrix and calculate all unknown 'x'. If it is not possible to calculate them, I have to estimate the missing x, and solve it with something like a Netwon-Raphson method. But that will propably be in a later question.
Thank you for answering.
Phillipphttps://kr.mathworks.com/matlabcentral/profile/authors/17567867-phillipp