https://au.mathworks.com/matlabcentral/answers/questions.atomMATLAB Answers — New Questions2018-04-23T05:29:23Ztag:au.mathworks.com,2005:Question/3967162018-04-23T04:43:00Z2018-04-23T05:28:51ZWhy does my resulting matrix only contain the last value of the iteration for p and q?<pre class="language-matlab">phi(1,1) = 3;
</pre><pre class="language-matlab">phi(2,1) = 2;
</pre><pre class="language-matlab">phi(3,1) = 1;
</pre><pre class="language-matlab">phi(5,1) = 6;
</pre><pre class="language-matlab">g = [1 2 3; 4 5 6; 7 8 9];
</pre><pre class="language-matlab">for j = [1,2,5]
</pre><pre> for m = [1,2,5]</pre><pre> for p = 1:3</pre><pre> for q = 1:3</pre><pre> k(phi(j),phi(m)) = g(p,q);</pre><pre> end</pre><pre> end</pre><pre> end
end</pre>Celso Carranzahttps://au.mathworks.com/matlabcentral/profile/authors/6475859-celso-carranzatag:au.mathworks.com,2005:Question/3966992018-04-23T02:43:22Z2018-04-23T05:29:23ZCan't open created PDF<p>I'm making a program in GUIDE that creates regressions based off given data and plots them.
For each plot, a log is created that details the type of plot, its form/constants, and MSE.
I was able to successfully do this using a .txt and the following code.
A button is pressed to begin the file, using the code</p><pre class="language-matlab">fid = fopen('Logfile.txt','w');
fid = fclose(fid);
</pre><p>Then, each time a regression is made, the following function is called:</p><pre> function [ ] = logger( message, fileName )
fileID = fopen(fileName,'a');
fprintf(fileID,message);
fclose(fileID);
end</pre><p>Where each message is a variable made previously and appended to the file.
I also intend to save each figure, which brings me to my point. When replacing .txt with .pdf everywhere in the code, I am able to make the .pdf file, but it says damaged and I can't open it. Furthermore, I'm not sure how to save the plot in the GUIDE window to a PDF or how to append a PDF as well. Thanks for the help</p><p>EDIT: I am now aware that the procedure for appending .txt files does not apply to PDFs. I'm still looking for a way to compile the figures, and then combine it with the .txt to make a .pdf</p>Reed Torres Torreshttps://au.mathworks.com/matlabcentral/profile/authors/10866436-reed-torres-torrestag:au.mathworks.com,2005:Question/3967212018-04-23T05:18:34Z2018-04-23T05:27:32ZHow to retrain existing and trained Neural Network without destroying trained content?<p>Matlab train() function used for training the neural network initializes all weights and other internal parameters of the network at the beginning.
I would like to take a trained network and train it further using new set of data without reinitializing and starting from scratch (destroying the trained net basically). How do I do it ?
Is there a way to use existing train() function or is there some re-train() function or do I need to build my own custom solution ? The last option seems unlikely, given the amount of the existing Matlab code.
Please advise,
Thanks,
Mirek Wilmer <a href = "mailto:mirek.wilmer@gmail.com">mirek.wilmer@gmail.com</a></p>Mirek Wilmerhttps://au.mathworks.com/matlabcentral/profile/authors/4701982-mirek-wilmertag:au.mathworks.com,2005:Question/3964922018-04-21T19:03:19Z2018-04-23T05:26:59ZODE45 for a second order differential equation<p>I have a second order differential equation : y''=(2*y)+(8*x)*(9-x); Boundary Conditions y(0)=0 , y(9)=0
Need to solve the diff eq using ode45.</p><p>I've tried watching a bunch of tutorials but I just cannot seem to figure out how the function is written as a column vector [y';y'']. I don't understand it at all and that might make this query vague too.</p><p>Hope someone can help with the code or the explanation on how to solve the above.</p><p>Thank you</p>Remston Martishttps://au.mathworks.com/matlabcentral/profile/authors/12510127-remston-martistag:au.mathworks.com,2005:Question/3967182018-04-23T04:51:24Z2018-04-23T05:24:46Zhow to solve this error ? Error using horzcat Dimensions of matrices being concatenated are not consistent.<p>Here is the code:</p><pre class="language-matlab">clear all;
a = 1;
b = 2;
</pre><pre class="language-matlab">alpha = 2;
</pre><pre class="language-matlab">format longG;
</pre><pre class="language-matlab">[w,t] = RungeKutta(a,b,0.25,alpha);
combinedArray = [(0:4)' t' w'];
</pre><pre class="language-matlab">T3 = array2table(combinedArray);
T3.Properties.VariableNames = {'i','t_i','w_i'};
filename1 = 'Table1.csv';
writetable(T3,filename1);
</pre><pre class="language-matlab">figure('DefaultAxesFontSize',16);
plot(t,w,'LineWidth',2);
xlabel('t');
ylabel('y');
</pre><pre class="language-matlab">NArray = zeros(1,5);
hArray = zeros(1,5);
errorArray = zeros(1,5);
hFourthArray = zeros(1,5);
</pre><pre class="language-matlab">for k = 1:5
h = 1/(2^k);
N = (b-a)/h;
[w,t] = RungeKutta(a,b,h,alpha);
</pre><pre> error = abs(w(N+1) - TrueSolution(t(N+1)));
NArray(k) = N;
hArray(k) = h;
errorArray(k) = error;
hFourthArray(k) = h^4;
end
combinedArray2 = [hArray' errorArray'];</pre><pre class="language-matlab">T4 = array2table(combinedArray2);
T4.Properties.VariableNames = {'h','Error'};
filename2 = 'Table2.csv';
writetable(T4,filename2);
</pre><pre class="language-matlab">figure('DefaultAxesFontSize',16);
loglog(NArray,errorArray,NArray,hFourthArray,'LineWidth',2);
xlabel('n');
legend('Error','10h^4');
</pre>Crystal Thomspsonhttps://au.mathworks.com/matlabcentral/profile/authors/11515111-crystal-thomspsontag:au.mathworks.com,2005:Question/3909392018-03-27T10:24:39Z2018-04-23T05:23:53Zhow to deploy sensor nodes randomly in a matrix 100x100<p>how to deploy sensor nodes randomly in a matrix 100x100 ?</p>Debalina Palhttps://au.mathworks.com/matlabcentral/profile/authors/12303270-debalina-paltag:au.mathworks.com,2005:Question/3967202018-04-23T05:13:33Z2018-04-23T05:23:31Zadjusting the x,y axes ratios in plot (2d)<p>I want to adjust the x and y axis such that the graph has an aspect ratio of 1:1 (a square). Also, i want the x- and y-axes to have tick marks of the same distance (for example: x marks 16, 18, 20, etc; y marks 2 4 6, etc in distances of 2).</p><p>insights welcome</p>CLARK KENDRICK GOhttps://au.mathworks.com/matlabcentral/profile/authors/7426914-clark-kendrick-gotag:au.mathworks.com,2005:Question/3964652018-04-21T14:26:40Z2018-04-23T05:14:29ZWe use imshow to show matrix constantly and getdata to take photos for every matrix in a loop. However , the imshow can't work in the loop until we pause the project.What can we do to change the situation? Thanks<p>We use imshow to show matrix constantly and getdata to take photos for every matrix in a loop. However , the imshow can't work in the loop until we pause the project.What can we do to change the situation? Thanks</p><pre> set(gcf,'outerposition',get(0,'screensize'));
figure('toolbar','none', 'menubar','none','units','normalized','outerposition',[0 0 1 1])</pre><pre> for k =1:400
A = HA(k,:)
A = reshape(A,20,20)
imshow(A,'InitialMagnification','fit');</pre><pre> pause(pause_time)</pre><pre> imgO=getdata(vid,1,'uint8')</pre><pre> imwrite(imgO,['stima_',sprintf('%d',k),'.jpg']);</pre><pre> k = k + 1
end</pre>yuxiang baohttps://au.mathworks.com/matlabcentral/profile/authors/12567985-yuxiang-baotag:au.mathworks.com,2005:Question/3966692018-04-22T22:07:34Z2018-04-23T05:12:47ZConverting an equation into MATLAB code<p>I am trying to write a code that calculates the accuracy of my network using sMAPE. The equation is depicted here:</p><img src = "/matlabcentral/answers/uploaded_files/114290/smape.png"><p>(Y is actual value, F is forecast value, n is the amount of data)</p><p>I have written this code (I have 25 data):</p><pre class="language-matlab">e= gsubtract(output,y);
y= net(input);
accuracy = (0.08*mean(abs(e./(abs((output)+(y))))))
</pre><p>"output" on the code above is the target, "y" is the output (sorry for the misleading name with the actual output)
Assuming I use the equation above as a reference, is this code correct?</p>NeverPerfecThttps://au.mathworks.com/matlabcentral/profile/authors/9491225-neverperfecttag:au.mathworks.com,2005:Question/3230282017-02-02T10:28:31Z2018-04-23T05:10:18Ztransmissibility force script matlab<p>i tried do reproduce a plot using force transmissibility " Ft/Ky " law (in pdf )but when i plot the graph in matlab is not the same as pdf i don't know where i made a mistake in matlab script..!</p><p><<</p><img src = "/matlabcentral/answers/uploaded_files/68830/Sans%20titre20170202111705.jpg"><p>>></p><img src = "/matlabcentral/answers/uploaded_files/68832/Sans%20titre20170202111518.jpg"><img src = "/matlabcentral/answers/uploaded_files/68831/Sans%20titre20170202111725.jpg">nassim khelloufhttps://au.mathworks.com/matlabcentral/profile/authors/9646765-nassim-khellouftag:au.mathworks.com,2005:Question/3967192018-04-23T05:05:02Z2018-04-23T05:09:03ZArray indices must be positive integers or logical values.<p>I am not sure why my code is coming up with this:</p><pre class="language-matlab">Array indices must be positive integers or logical values.
</pre><pre class="language-matlab">Error in P9_07_Casey_Galerneau (line 18)
monthly =
principal*((interest(1+interest)^number_payments)/((1+interest)^number_payments)-1);
>>
</pre>Casey Galerneauhttps://au.mathworks.com/matlabcentral/profile/authors/12692097-casey-galerneautag:au.mathworks.com,2005:Question/3967092018-04-23T03:43:49Z2018-04-23T05:00:58ZHow to make a matrix based on other values in a matrix that 'match'<p>Hi,
I'm trying to create a matrix that is based on the values of another matrix and based on the number positioning of it's current matrix.</p><p>Here is where we start (MatrixONE):</p><img src = "/matlabcentral/answers/uploaded_files/114305/matlabone.PNG"><p><b>The above matrix was done with the help of Stephen Cobeldick.</b></p><p>These are the values I require (MatrixTWO):</p><p>[ 1 100 120 ; 2 200 240 ; 3 300 360 ; 4 400 480 ]</p><p>For example, in the first row, first column. There is a value of 2. This value needs to collect the value from the second row, second column of MatrixTWO (Which is 200). Now in the first row of the second column is also a value of 2. However that value needs to collect the value 240. With negative numbers, they do the exact same thing but make the number negative. I've provided a picture of what the output should look like.</p><p>This is what the output should look like (MatrixTHREE):</p><img src = "/matlabcentral/answers/uploaded_files/114307/matlabthree.PNG"><p>One final note: This cannot be hard coded and must work 'universally'. This is where I get completely thrown off course.</p><p>I look forward to reading some answers!</p>Darrian Lowhttps://au.mathworks.com/matlabcentral/profile/authors/12686349-darrian-lowtag:au.mathworks.com,2005:Question/3962172018-04-20T05:07:49Z2018-04-23T05:00:44ZWarning matrix is singular to working precision<p>I have rows of 2D data points. I want to get a interpolating B-spline surface(interpolating each row of data point to get interpolating B-spline curves and then interpolating curves to get B-spline surface) so I extended the data to 3D (by adding z-coordinate). But when finding the control points by solving linear system of equation (Bx = D, D:data-points, B:b-spline basis matrix,), I get warning "Matrix is singular to working precision" and almost all the control points are 0.0000 times e+06 after a few starting ones.</p>Lokesh Rakawathttps://au.mathworks.com/matlabcentral/profile/authors/7101000-lokesh-rakawattag:au.mathworks.com,2005:Question/3965842018-04-22T11:09:33Z2018-04-23T04:58:44ZAssigning only 0s and 1s for multiobjective optimization through GA.<p>For the following function, 'gamultiobj' is to be applied.</p><p>Constraint for x(3), x(4), x(5) and x(6) is such that only one of them must be equal to 1 while other three must be 0 at a time.</p><p>x(1) and x(2) can take any integer. Can anybody help me in solving this problem. ('IntCon' is not allowed in 'gamultiobj')</p><pre> function [F,R] =gam(x)
F=73.4 - 0.00569 .*x(1) + 0.05160 .*x(2) - 6.73 .*x(3) - 1.67 .*x(4) + 0.02 .*x(5)- 4.63 .*x(6);
R=939 - 0.0509.*x(1) + 0.1329.*x(2) - 203.4.*x(3) + 28.0.*x(4) + 0.04.*x(5)- 31.0.*x(6);
end</pre>Muhammed Muazhttps://au.mathworks.com/matlabcentral/profile/authors/12625957-muhammed-muaztag:au.mathworks.com,2005:Question/3967152018-04-23T04:22:55Z2018-04-23T04:51:59ZNumber of inputs does not match net.numInputs<p>I have a network with 7 inputs, 2 layers and 2 outputs.</p><pre class="language-matlab">biasConnect = [0;0];
inputConnect = [1 1 1 1 1 1 1; 0 0 0 0 0 0 0];
layerConnect = [0 0; 1 0];
outputConnect = [0 1];
net = network(7,2,biasConnect,inputConnect,layerConnect, outputConnect);
</pre><p>I'm trying to get the outputs for a single set of inputs.</p><pre class="language-matlab">input = [s1;s2;s3;s4;s5;M;S];
Y = sim(net,input);
</pre><p>I get the error; Error using network/sim (line 266),Number of inputs does not match net.numInputs.</p><p>I tried running the sample code found at <a href = "https://www.mathworks.com/help/nnet/ref/network.html">https://www.mathworks.com/help/nnet/ref/network.html</a></p><pre class="language-matlab">net = network(1,2,[1;0],[1; 0],[0 0; 1 0],[0 1]);
p = [0.5; -0.1];
y = sim(net,p);
</pre><p>And I get similar error;Error using network/sim (line 266), Input data sizes do not match net.inputs{1}.size.</p><p>Both sets of code seem to have the appropriate sized input data. I have tried transposing the input data.</p>Harki Bainshttps://au.mathworks.com/matlabcentral/profile/authors/8330066-harki-bainstag:au.mathworks.com,2005:Question/3909972018-03-27T13:46:56Z2018-04-23T04:50:42ZFFT of a sinusoidal function<p>Following the 1st example that appears on your website (https://uk.mathworks.com/help/matlab/ref/fft.html), it is not clear to me why if I try to speed up the fft by introducing a power of 2, I do not recover the correct amplitudes.</p><p>In other words, the following code works fine, i.e. it captures the original frequencies, 0.7 and 1:</p><pre class="language-matlab">Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1500; % Length of signal
t = (0:L-1)*T; % Time vector
S = 0.7*sin(2*pi*50*t) + 1*sin(2*pi*120*t);
Y = fft(S);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1,'k')
</pre><p>but the following code, where I try to speed up the fft computation, does not capture the correct amplitudes. In fact, the amplitudes that I get are 0.6 and 0.95:</p><pre class="language-matlab">Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1500; % Length of signal
t = (0:L-1)*T; % Time vector
S = 0.7*sin(2*pi*50*t) + 1*sin(2*pi*120*t);
n = 2^nextpow2(L);
Y = fft(S,n);
P2 = abs(Y/L);
P1 = P2(1:n/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(n/2))/n;
plot(f,P1,'k')
</pre><p>I believe this occurs because for frequencies different from 50Hz and 120 Hz the amplitude is not zero, thus to preserve the energy content the real amplitudes (of 50Hz and 120Hz) are lower than the correct values (0.7 and 1). Do you know why in this case the introduction of n creates problems? When can I not use this technique? The same occurs for noisy signals.</p><p>Thanks</p>Francesco Garitahttps://au.mathworks.com/matlabcentral/profile/authors/11929223-francesco-garitatag:au.mathworks.com,2005:Question/3967172018-04-23T04:43:37Z2018-04-23T04:44:34ZThingSpeak Channel Status Update field<p>Hi everyone,</p><p>I wanted to update this Channel Status Update field in my ThingSpeak channel, and I used this piece of code:</p><p>webwrite('http://api.thingspeak.com/update','api_key',writeApiKey,'status','good');</p><p>the code works fine but my channel never display "good" in status field, can anyone tell me why?</p><p>Thanks.</p>Alex kewhttps://au.mathworks.com/matlabcentral/profile/authors/10200872-alex-kewtag:au.mathworks.com,2005:Question/3967122018-04-23T04:03:41Z2018-04-23T04:43:45ZChanging the value in the popupmenu<p>The first item of my popupmenu is an instruction so it really isn't a value, but MATLAB seems to take it as a value whenever i accidentally pick it. Let's say I want to assign "5" to my second item, how do I make it show 5 instead of 2 because whenever I do the calculation MATLAB uses 2 instead of 5.</p>Quan Seahhttps://au.mathworks.com/matlabcentral/profile/authors/12269194-quan-seahtag:au.mathworks.com,2005:Question/3966912018-04-23T01:21:03Z2018-04-23T04:42:23ZHow do I set the plot color and line style of several data sets using a cell array?<p>I am plotting several sets of data on a single plot and would like to control the color and linestyle of each line using a cell array like this:</p><pre class="language-matlab">figure(1)
hold on
grid on
xlim([0 60])
colorVec = {'b', 'r', 'y', 'p', 'g', 'c'};
linVec = {'--', '-.','--', '-.','--', '-.'};
</pre><pre class="language-matlab">yyaxis left
plot(tvar,Ts1(:,:),'Color',colorVec{:},'LineStyle',linVec{:},'LineWidth',2,'MarkerSize',5)
hold off
</pre><p>However, the above code does not work and produces an error. Can anyone help me with the syntax of what I am trying to accomplish? Thank You in advance.</p>Eugene Chohttps://au.mathworks.com/matlabcentral/profile/authors/5946373-eugene-chotag:au.mathworks.com,2005:Question/3967112018-04-23T04:01:29Z2018-04-23T04:37:55ZCan i make this kind of graph in matlab<img src = "/matlabcentral/answers/uploaded_files/114310/%C4%91%E1%BB%93%20th%E1%BB%8B.PNG">pham liemhttps://au.mathworks.com/matlabcentral/profile/authors/10600427-pham-liemtag:au.mathworks.com,2005:Question/3967022018-04-23T03:14:35Z2018-04-23T04:36:36ZWhat is the concept behind symbolic toolbox<p>Using normal command we can not calculate factorial(200), it gives inf, but using symbolic toolbox we are able to calculate factorial (sym(200)),</p><p>My question is how symbolic toolbox is able to calculate whereas normally we cant, what is the concept behind this</p>Parikshit Sharmahttps://au.mathworks.com/matlabcentral/profile/authors/10929531-parikshit-sharmatag:au.mathworks.com,2005:Question/3966972018-04-23T02:30:33Z2018-04-23T04:30:56ZCould anyone help me to overcome the issue.<p>When i run the code it is getting executed as continue entering the statement.
when i type any command in the command window it was not getting executed.
could anyone help me how to overcome it.</p>jaah navihttps://au.mathworks.com/matlabcentral/profile/authors/11695462-jaah-navitag:au.mathworks.com,2005:Question/3956742018-04-18T06:13:17Z2018-04-23T04:26:07Zwhat is wrong with this code?<p>I have been working on this code and i encountered this unsolvable error. Please help !</p><p>code :</p><pre class="language-matlab">clc
</pre><pre class="language-matlab">clear all
</pre><pre class="language-matlab">close all
</pre><pre class="language-matlab">%% Parameters of Blasius Equation
</pre><pre class="language-matlab">U_inf = 1;
</pre><pre class="language-matlab">L = 10;
</pre><pre class="language-matlab">mu = 1.789E-5;
</pre><pre class="language-matlab">rho = 1.225;
</pre><pre class="language-matlab">nu = mu/rho;
</pre><pre class="language-matlab">A = sqrt(nu/U_inf);
</pre><pre class="language-matlab">h = 0.01;
</pre><pre class="language-matlab">%% Numerical Solution of Blasius Equation Using Runge-Kutta
</pre><pre class="language-matlab">f1 = @(x, y1, y2, y3) y2;
</pre><pre class="language-matlab">f2 = @(x, y1, y2, y3) y3;
</pre><pre class="language-matlab">f3 = @(x, y1, y2, y3) -y1*y3;
</pre><pre class="language-matlab">eta = 0:h:10;
</pre><pre class="language-matlab">x = 0:h:10;
</pre><pre class="language-matlab">y1(1) = 0;
</pre><pre class="language-matlab">y2(1) = 0;
</pre><pre class="language-matlab">y3(1) = 0.4696;
</pre><pre class="language-matlab">for i = 1:(length(eta)-1)
</pre><pre class="language-matlab">a = h.*[f1(eta(i), y1(i), y2(i), y3(i)), f2(eta(i), y1(i), y2(i), y3(i)), f3(eta(i), y1(i), y2(i), y3(i))];
</pre><pre class="language-matlab">b = h.*[f1(eta(i), y1(i)+a(1)/2, y2(i)+a(2)/2, y3(i)+a(3)/2), f2(eta(i)+h/2, y1(i)+a(1)/2, y2(i)+a(2)/2, y3(i)+a(3)/2), f3(eta(i)+h/2, y1(i)+a(1)/2, y2(i)+a(2)/2, y3(i)+a(3)/2)];
</pre><pre class="language-matlab">c = h.*[f1(eta(i), y1(i)+b(1)/2, y2(i)+b(2)/2, y3(i)+b(3)/2), f2(eta(i)+h/2, y1(i)+b(1)/2, y2(i)+b(2)/2, y3(i)+b(3)/2), f3(eta(i)+h/2, y1(i)+b(1)/2, y2(i)+b(2)/2, y3(i)+b(3)/2)];
</pre><pre class="language-matlab">d = h.*[f1(eta(i), y1(i)+c(1), y2(i)+c(2), y3(i)+c(3)), f2(eta(i)+h, y1(i)+c(1), y2(i)+c(2), y3(i)+c(3)), f3(eta(i)+h, y1(i)+c(1), y2(i)+c(2), y3(i)+c(3))];
</pre><pre class="language-matlab">y3(i+1) = y3(i)+ 1/6*(a(3)+2*b(3)+2*c(3)+d(3));
</pre><pre class="language-matlab">y2(i+1) = y2(i)+ 1/6*(a(2)+2*b(2)+2*c(2)+d(2));
</pre><pre class="language-matlab">y1(i+1) = y1(i)+ 1/6*(a(1)+2*b(1)+2*c(1)+d(1));
</pre><pre class="language-matlab">end
</pre><pre class="language-matlab">%% Plotting and Visualization
</pre><pre class="language-matlab">figure(1)
</pre><pre class="language-matlab">plot(eta,y1,eta, y2, eta, y3, 'LineWidth', 2)
</pre><pre class="language-matlab">xlim([0 10])
</pre><pre class="language-matlab">title('Solution of Blasius eqution', 'FontSize', 14);
</pre><pre class="language-matlab">xlabel('f, f'' and f''''', 'FontSize', 20);
</pre><pre class="language-matlab">ylabel('\eta', 'FontSize', 20);
</pre><pre class="language-matlab">grid on
</pre><pre class="language-matlab">Legend1 = {'f(\eta)', 'f''(\eta)', 'f''''(\eta)'};
</pre><pre class="language-matlab">legend(Legend1, 'FontSize', 14);
</pre><pre class="language-matlab">syms q a b pr a1 b1;
pr=1;
a=((diff([y2],2)).^(pr));
b=((diff([y2],2)).^(pr));
a1=int(a,'eta',0,10);
b1=int(b,'eta',0,inf);
q=a1/b1
</pre>Vetrichelvan Pugazendihttps://au.mathworks.com/matlabcentral/profile/authors/9639878-vetrichelvan-pugazenditag:au.mathworks.com,2005:Question/3967142018-04-23T04:11:53Z2018-04-23T04:16:31ZHow to write a program that read block by block ?<p>I am having a matrix of size 512x512. Now I have to extract 16x16 blocks from the matrix and encode each of the blocks. Now there will be a total of 1024 blocks. How to write a program to extract each of the blocks?</p>nur aqilahttps://au.mathworks.com/matlabcentral/profile/authors/11618331-nur-aqilatag:au.mathworks.com,2005:Question/3967132018-04-23T04:10:38Z2018-04-23T04:10:38ZIs this okay to use multiple 2D images in "CNN with multiple channel", which is provided in matlab 2018a?? <p>Now, Matlab 2018a provided the 2D CNN with multiple channels. (Thank you!)</p><p>Right now, i am trying to apply CNN in 3D images (MRI data).</p><p>I am planning to use 3D images as (2D x z stacks) thus they are all grey scaled colored at different z axis.</p><p>My question is that is this okay to use multiple 2D images in "CNN with multiple channel", because my 2D images are not images with different colors but images with grey scaled color at different z axis.</p><p>Please help. Thank you</p>Hang-Rai Kimhttps://au.mathworks.com/matlabcentral/profile/authors/8029072-hang-rai-kimtag:au.mathworks.com,2005:Question/3967072018-04-23T03:41:47Z2018-04-23T04:06:15ZHow can I save a recorded audio as .mp3 using matlab and load it then play it?<p>How can I save a recorded audio as .mp3 using matlab and load it then play it.</p><p>here is my code so far:</p><pre class="language-matlab">recObj = audiorecorder(8000,8,1);
</pre><pre class="language-matlab">disp('Start speaking.');
</pre><pre class="language-matlab">recordblocking(recObj, 5);
</pre><pre class="language-matlab">disp('End of Recording.');
</pre><pre class="language-matlab">y = getaudiodata(recObj);
</pre><pre class="language-matlab">plot(y);
</pre>vince de verahttps://au.mathworks.com/matlabcentral/profile/authors/12683314-vince-de-veratag:au.mathworks.com,2005:Question/3967002018-04-23T02:57:31Z2018-04-23T04:01:31ZPlay low sampling frequency audio in matlab<p>I have a 6467584*1 double array containing audio data. The sampling frequency for the data is 256. When I try to play the audio using the soundsc function it shows the following error :</p><pre> % Error using sound (line 76) Device Error: Invalid sample rate. Error in soundsc (line 55)
sound(varargin{:});</pre><p>Is there any function that I can use in MATLAB to play audio?</p>arun sebastianhttps://au.mathworks.com/matlabcentral/profile/authors/9096637-arun-sebastiantag:au.mathworks.com,2005:Question/3967102018-04-23T03:53:28Z2018-04-23T04:00:14Zhow to make contour from 3 columns matrix<p>Hi all. I'have problem..</p><p>I have mat file with 4 columns (long, lat, time, and data).. ignored about the time, so I'm focused only long, lat, and time. The question is how I'm making contour (pcolor with the 1st,2nd, and 4th use only), because the column for long it doesn't look nice grid.</p><p>Tks for your help..</p>eko supriyadihttps://au.mathworks.com/matlabcentral/profile/authors/2451672-eko-supriyaditag:au.mathworks.com,2005:Question/3501062017-07-25T02:12:11Z2018-04-23T03:59:35ZHow to apply Matlab CNN code on an input image with 6 channels<p>I have currently applied the Matbal CNN function to train my research data. Unlike, the Matlab 'lettersTrainSet'with a size of 28x28x1x1500 (4-D array), the input train data of my experiment have a size of 7x7x6x30,000.
The problem I have encountered is that while running the 'trainNetwork' function, Matlab shows me an error: *Error using trainNetwork>iAssertValidImageArray (line 575)
X must be a 4-D array of images.</p><p>Error in trainNetwork>iParseInput (line 329)
iAssertValidImageArray( X );</p><p>Error in trainNetwork (line 68)
[layers, opts, X, Y] = iParseInput(varargin{:});*</p><p>However, the same training data with 3 channels or 1 channels I can run the CNN code without any error message.
It will be a great help if anyone can suggest how to use image data with more than 3 channels in Matlab for CNN classification.</p>Chandrama Sarkerhttps://au.mathworks.com/matlabcentral/profile/authors/7638043-chandrama-sarkertag:au.mathworks.com,2005:Question/3966922018-04-23T01:48:37Z2018-04-23T03:56:10ZHow do I uses the information from this code in the optimization tool?<pre> clear all;
clc;</pre><pre> Fi=1000;</pre><pre> Se= 50;
Su= 450;</pre><pre> C= 2/3;
nf=[];
Pmax= 3662.5;
Pmin= 1000;</pre><pre> D=2:01:6;
for k = 1:numel(D)
A= 0.25*pi*(D(k))^2;
siga= ((C*Pmax+Fi)-(C*Pmin+Fi))/2*A;
sigm= ((C*Pmax+Fi)+(C*Pmin+Fi))/2*A;
sigi= sigm-siga;
nf(k)= (Se*(Su-sigi))/(siga*(Su+Se));
end
figure(1)
plot(D,nf)
xlabel('D');
ylabel('nf');</pre>Liam Swifthttps://au.mathworks.com/matlabcentral/profile/authors/6791362-liam-swifttag:au.mathworks.com,2005:Question/3967032018-04-23T03:17:49Z2018-04-23T03:53:46Zhow to make subplot of sequence column automatically?<p>Hi, I am not sure that this typical question has been asked. I have searched for it and not find any that suit to my problem. I have 3 files containing 12 column, in which the first column is X-axis value. I plan to make subplot 11-row and 3-column, as this sequence: [A=file1;B=File2;C=File3]</p><pre class="language-matlab">+++ A:,2 +++ B:,2 +++ C:,2 +++
+++ A:,3 +++ B:,3 +++ C:,3 +++
+++ .... +++ .... +++ .... +++
+++ A:,12 +++ B:,12 +++ C:,12 +++
</pre>Amra Rajulihttps://au.mathworks.com/matlabcentral/profile/authors/11899166-amra-rajulitag:au.mathworks.com,2005:Question/3966952018-04-23T02:08:24Z2018-04-23T03:53:33ZHow can i compare an image to a preexisting one, looking for differences?<p>i'm quite new to the image analyzing part in MATLAB so i need some help, i'm trying to detect cataracts in the eye bye comparing images taken from patients to a preexisting image of a healthy eyes.
what i would think of is grey scaling both images to detect the differences since cataracts have different colors then the eye. but i don't know what functions to use in MATLAB.
Thanks in advance</p>Ahmed Gaberhttps://au.mathworks.com/matlabcentral/profile/authors/7733307-ahmed-gabertag:au.mathworks.com,2005:Question/3967082018-04-23T03:42:14Z2018-04-23T03:42:14ZMatlab function calls in State chart during the 'exit' and 'transition' are not working<p>1. The function calls during the 'exit' and 'transition' are not working. In the attached model, I am receiving the values 1 and 4 on the scope. The function calls for values 2 and 3 written on exit and transition are not receiving.The message is receiving on the generated code. Why the function calls written on the exit or transition are not working?</p><p>2. There is good time delay between the function call and getting the output on the output port/scope(Refer the same model). In one of the model that I work, even if the function is invoked, the output port data is changed after several step only. What might be the reason?</p>Varunjith Vijayanhttps://au.mathworks.com/matlabcentral/profile/authors/10454084-varunjith-vijayantag:au.mathworks.com,2005:Question/3967052018-04-23T03:27:22Z2018-04-23T03:38:08ZI have problem in importing excel file containing variable.<pre class="language-matlab">clc;
clear all;
close all;
</pre><pre class="language-matlab">syms T h rho F1 F2
mem=2 %number of elements
</pre><pre class="language-matlab">%element k matrix
k=h\T*[1 -1;-1 1];
m=(rho*h/6)*[2 1;1 2]
</pre><pre class="language-matlab">% assembling global matrix
tightwire=importdata('TightWire.xlsx')
S=zeros(mem)
M=zeros(mem)
U=tightwire(mem,1:mem+1)
</pre><pre class="language-matlab">%elementnumbering
nod=[1:1:mem+1];
c=cell(mem,1);
for t=1:mem
c{t}=[nod(t) nod(t)+1];
end
</pre><pre class="language-matlab">for k=1:mem
l=c{k}
for i=1:mem+1
for j=1:mem+1
for o=1:2
for p=1:2
if i==l(o)
if j==l(p)
S(i,j)=S(i,j)+k(o,p);
M(i,j)=M(i,j)+m(o,p);
end
end
end
end
end
end
end
</pre>Prateek jainhttps://au.mathworks.com/matlabcentral/profile/authors/12424753-prateek-jaintag:au.mathworks.com,2005:Question/3965472018-04-22T05:03:14Z2018-04-23T03:37:59ZHow to Record audio and save it into two different hz simultaneously in matlab<p>i want to record using audio recorder and record only one audio with two different Hz
I used this code and instead of recording only one audio it records 2 please help</p><p>recObj = audiorecorder(8000,8,1)
recObj2 = audiorecorder(1000,8,1)
disp('Start speaking.')
recordblocking(recObj2, 5);
recordblocking(recObj, 5);
disp('End of Recording.');
play(recObj2);</p><p>sorry for the bad english</p>vince de verahttps://au.mathworks.com/matlabcentral/profile/authors/12683314-vince-de-veratag:au.mathworks.com,2005:Question/3966892018-04-23T01:03:47Z2018-04-23T03:35:35ZNeed to combine two matrix<p>Hi,
I have two matrices P= 1 2;3 4;5 6; Q= 7 8;9 10;11 12;</p><p>I want the result</p><p>R=</p><pre> {[1 7] [2 8];
[3 9] [4 10];
[5 11] [6 12]};</pre><p>Can any one help me?</p>Santhosh Chandrasekarhttps://au.mathworks.com/matlabcentral/profile/authors/10517346-santhosh-chandrasekartag:au.mathworks.com,2005:Question/3966902018-04-23T01:06:24Z2018-04-23T03:35:34Zelement-by-element sum of cell array<p>I have a cell A of size 100:
A{1,1}=[1 2 3 4];
A{1,2}=[5 6 7 8];
...A{1,100}=[10 11 12 13];</p><p>I want to take element-by-element sum.
SUMA should be a vector containing 4 elements where 1st element is sum of 1st entry of all A{1,i} elements, where i=1 to 100 and so on.
How can i do this?</p>Haneya Qureshihttps://au.mathworks.com/matlabcentral/profile/authors/10181972-haneya-qureshitag:au.mathworks.com,2005:Question/3967062018-04-23T03:28:35Z2018-04-23T03:34:21ZHow to assign values to popup menu in GUI?<p>I have a GUI to calculate the resistance of a resistor based on the number of bands and the color orders. I have 10 different colours, such as black, brown, red etc. I had tried to assign values to each color by using the following codes:</p><pre class="language-matlab">contents = cellstr(get(hObject,'string'));
popChoice = contents(get(hObject,'value'));
if strcmp(popChoice,'Black')
popVal = 0;
elseif strcmp(popChoice,'Brown')
popVal = 10;
elseif strcmp(popChoice,'Red')
popVal = 20;
elseif strcmp(popChoice,'Orange')
popVal = 30;
elseif strcmp(popChoice,'Yellow')
popVal = 40;
elseif strcmp(popChoice,'Green')
popVal = 50;
elseif strcmp(popChoice,'Blue')
popVal = 60;
elseif strcmp(popChoice,'Violet')
popVal = 70;
elseif strcmp(popChoice,'Grey')
popVal = 80;
elseif strcmp(popChoice,'White')
popVal = 90;
end
assignin('base','SecondColor',popVal)
</pre><p>The codes I used above actually works but all it does is saved the value into workspace and I have no idea how to use the value that's saved in the workspace to do calculation. Additionally, I had another function file that will do all the calculation based on the information gathered but I also have no clue on how to actually use it in GUI.Please help.</p>Quan Seahhttps://au.mathworks.com/matlabcentral/profile/authors/12269194-quan-seahtag:au.mathworks.com,2005:Question/3967042018-04-23T03:22:27Z2018-04-23T03:22:27Z My question is that if there is a connection selector in Simulink, I can choose different connection at different time? Or any other ways can help me with the problem? My model as the following figure shows,the red part is what I need to solve.<img src = "/matlabcentral/answers/uploaded_files/114303/connect%20select.png">fulai liuhttps://au.mathworks.com/matlabcentral/profile/authors/11764057-fulai-liutag:au.mathworks.com,2005:Question/3962032018-04-20T02:57:53Z2018-04-23T03:21:11ZMATLAB 2016a version takes up too much memory<p>I installed MATLAB 2016a version in two computer. Why does the laptops take up 11G of memory and the desktop only 3G?</p>Ailsa Yanghttps://au.mathworks.com/matlabcentral/profile/authors/4865804-ailsa-yangtag:au.mathworks.com,2005:Question/3945532018-04-13T00:18:17Z2018-04-23T03:19:36ZCNN - training, cross-validating and testing procedure -procedure and issues<p>I know this is a fundamental question, but still I need to get a clear idea on this before I proceed further.</p><p>I have 8 subjects' data (images) with me: A,B,C,D,E,F,G,H. I have designed a CNN for a binary classification application. I train my CNN using 7 of the subjects (after balancing the minority class using oversampling technique). During training I use 80% of my data for training and 20% for cross-validation. I alter the hyper-parameters till I get a good cross-validation accuracy. Now that I am satisfied with my CNN's performance I test it with the left our subject.</p><p>Unfortunately, I get a low test-accuracy. After this what I did was, I went back to my CNN's hyper-parameters and modified my filter size and few other parameters and trained the CNN again with the same seven subjects till I got a good cross-validation accuracy and again tested it with the same left out subject as before. This time I got a good test accuracy.</p><p>I repeated this leave-one-out method(LOOM) training and testing process for the rest of the combination. fortunately for me, I got one set of hyper-parameters which worked for all LOOMs.</p><p>I was advised not to do this because it seems i am leaking testing information to CNN by adjusting my hyper-parameters based on my test results. Is my procedure faulty or is it right?</p><p>Kindly give your inputs.</p><p>Thanks for your time and help</p><p>--Venkat</p>Venkathttps://au.mathworks.com/matlabcentral/profile/authors/6240383-venkattag:au.mathworks.com,2005:Question/3960212018-04-19T09:26:08Z2018-04-23T03:19:04Zuse loadlibrary with a C dll several times, then throw an error " Error using loaddefinedlibrary"<p>I use the follow syntex:</p><pre class="language-matlab">loadlibrary('CDLL', 'EXPORT.h', 'mfilename', 'mxCDLL');
unloadlibrary('CDLL');
</pre><pre class="language-matlab">for i=1:1000
dll_name = 'CDLL';
if ~libisloaded(dll_name)
loadlibrary(dll_name, @mxCDLL);
end
end
</pre><p>and when the loop proceed the 495 time, it stoped, and throw an error "</p><pre class="language-matlab">Error using loaddefinedlibrary".
</pre><p>please help me, thank you very much!</p><p>ps: the CDLL.dll is programed by CUDA C, and I just load it and do nothing else.</p>David Liuhttps://au.mathworks.com/matlabcentral/profile/authors/12672975-david-liutag:au.mathworks.com,2005:Question/3967012018-04-23T03:12:59Z2018-04-23T03:17:27ZUsing the iterative variant of Gaussian Elimination to compress an image. In the for loop how do I get the code to perform the loop for when N=1 then replace the value A, with the value B you find for when N=1 for the iteration N=2 and so on?<pre class="language-matlab">if true
% code
end
F = imread('cameraman.tif'); % read the figure; F is matrix
figure, imshow(F); % plot the figure
A = dct2(F); % discrete cosine transform; idct2(A) will recover F;
% we apply GE to A;
N = 30; % the maximum steps
n = size(A);
i_row = 1:n(1);
j_col = 1:n(2);
B = zeros(n); % B stores the approximation to A;
for k = 1:N
[M,m] = max(abs(A(:)));
[i_row, j_col]= ind2sub(n,m);
B = A - A(:,j_col)*A(i_row,:)/A(i_row,j_col); %When I get to this point, how do I use this value of B in place of A to do the next iteration of the loop?
if B == zeros(n) % stopping check
</pre><pre> break;
end
end</pre>Justin Stanleyhttps://au.mathworks.com/matlabcentral/profile/authors/5622550-justin-stanleytag:au.mathworks.com,2005:Question/3951002018-04-15T22:52:11Z2018-04-23T03:15:48ZI have been stuck on the followng quesiton,please help.<p>We hope to generate two correlated random variables X and Y such that:
X � Exp(�lambda), Y � Weibull(�alpha; beta�), with � lambda= 2, � alpha= 2, � beta= 3:
Do the following for three diff�erent values for the correlation: �X;Y = 0.8; 0.2 and -0.8</p><p>(a) Use a Gaussian copula to generate N = 105 independent (X; Y ) pairs and estimate the
correlation using the simulated data.</p><p>(b) Plot all (X; Y ) pairs. Verify that the marginal distributions look appropriate.
(In
MATLAB use command \histogram(X)" or \scatterhist(X,Y)")</p>Abheet Khairahttps://au.mathworks.com/matlabcentral/profile/authors/11891139-abheet-khairatag:au.mathworks.com,2005:Question/3966542018-04-22T20:08:49Z2018-04-23T03:08:29ZA function that takes a string and returns the output file name, Part 2<p>Previously I asked,</p><p>"I want to have a function that takes a string S that defines the file name to be saved. For example, if S = 'Chicago' then it will save the file as Chicago.tif</p><pre class="language-matlab">saveas(gca, 'Chicago.tif');
</pre><p>Please advise."</p><p>Now suppose I want to have a function that takes a scalar a and a string 'Chicago' and have a plot of</p><p>y=a*x</p><p>and save it 'Chicago.tif.' Please advise.</p>alpedhuezhttps://au.mathworks.com/matlabcentral/profile/authors/10930090-alpedhueztag:au.mathworks.com,2005:Question/3966502018-04-22T20:02:51Z2018-04-23T03:08:08ZHow to pass string value from one callback function to another?<p>I am typing a code where in one callback function I am browsing for a audio file (.wav) by hitting one pushbutton and setting the filename in one of the edit box (edit6). Now, I want this audio file to be read when I hit the second pushbutton. What command should I use? so that I can read the audio file which i selected and plot its fft and time domain?
Here's the code..</p><pre class="language-matlab">% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
</pre><pre class="language-matlab">[filename,filepath]= uigetfile({'*.*';'*.wav';'*.m4a'});
fullname = [filepath filename];
set(handles.edit6,'string', filename) ;
</pre><pre class="language-matlab">% --- Executes on button press in button.
</pre><pre class="language-matlab">function button_Callback(hObject, eventdata, handles)
</pre><pre class="language-matlab">% hObject handle to button (see GCBO)
</pre><pre class="language-matlab">% eventdata reserved - to be defined in a future version of MATLAB
</pre><pre class="language-matlab">% handles structure with handles and user data (see GUIDATA)
</pre><pre class="language-matlab">data= audioread('C:\Users\Mohanish\Desktop\GA\Project\mohanish.wav');
L= length (data);
Y= fft(data)
P2= abs (Y/L)
P1= P2(1:L/23+1);
P1(2:end-1)= 2*P1(2:end-1)
figure= subplot('position', [0.56, 0.15, 0.4, 0.3]);
K= plot (P1);
title ('Frequency Domain')
xlabel('f(Hz)')
ylabel('|P1(f)|')
hold on
</pre><pre class="language-matlab">[y,Fs]= audioread('C:\Users\Mohanish\Desktop\GA\Project\mohanish.wav');
t= linspace(0,length(y)/Fs, length(y));
</pre><pre class="language-matlab">figure1= subplot('position', [0.10, 0.15, 0.4, 0.3]);
plot(t,y);
title ('Time Domain')
xlabel('Time (sec)')
ylabel('Amplitude')
</pre>mohanishhttps://au.mathworks.com/matlabcentral/profile/authors/12653114-mohanishtag:au.mathworks.com,2005:Question/3632132017-10-25T15:41:36Z2018-04-23T03:06:48ZTime Series Classification Advice<p>Hello, I'm fairly new to Machine Learning and I could do with some guidance on how to tackle a problem I'm on.</p><p>I have a significant number of time series data which I have measured and I want to develop an algorithm to classify them. A previous project I worked on allowed me to identify certain features in the data, and then use the Classification Learner to generate a model, which accurately predicted which set each time series belonged to.</p><p>At the MATLAB expo, I saw that with Deep Learning, I could have an algorithm automatically attempt to identify these features for me. The current data I have is much more complicated, making analysis by myself difficult. Similar to having MATLAB automatically identify the numbers 1 through 9 from a set of images, I want MATLAB to (for example), label a set of time series from 1 through 9.</p><p>How do I utilise the tools in the Neural Network toolbox to do this? I'm assuming I want to use the Clustering feature but I'm very overwhelmed by this.</p><p>Any advice would be much appreciated.</p><p>Thank you</p>DKhttps://au.mathworks.com/matlabcentral/profile/authors/9060935-dktag:au.mathworks.com,2005:Question/3965862018-04-22T11:24:48Z2018-04-23T03:03:21Zhow do i use a pushbutton from my GUI to perform some calculations calling from some popupmenus i have?<p>i am creating a GUI to calculate resistor values. i have 5 popupmenus to choose the colour of the bands and then i want a pushbutton to perform the calculations and then display the answer on the GUI.
here is the code for one of my popupmenus for an example.</p><pre class="language-matlab">% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
contents = cellstr(get(hObject,'String'));
popchoice = contents{get(hObject,'Value')};
if (strcmp(popchoice, 'Black'))
popVal = 0;
elseif (strcmp(popchoice, 'Brown'))
popVal = 1;
elseif (strcmp(popchoice, 'Red'))
popVal = 2;
elseif (strcmp(popchoice, 'Orange'))
popVal = 3;
elseif (strcmp(popchoice, 'Yellow'))
popVal = 4;
elseif (strcmp(popchoice, 'Green'))
popVal = 5;
elseif (strcmp(popchoice, 'Blue'))
popVal = 6;
elseif (strcmp(popchoice, 'Violet'))
popVal = 7;
elseif (strcmp(popchoice, 'Grey'))
popVal = 8;
elseif (strcmp(popchoice, 'White'))
popVal = 9;
end
assignin('base','popVal',popVal);
% this popupmenu is my band1 for the calculations
</pre><p>i have 5 of these popupmenus that are almost identical.</p><p>here are the equations i want the values from the popupmenus to go through the button and diplay the answer:</p><pre class="language-matlab">x = ((band1 * 100) + (band2 * 10) + band3) * 10^(bandmultiplier); % this is for 5 bands
</pre><p>and</p><pre class="language-matlab">x = ((band1 * 10) + band2) * 10^(bandmultiplier); % this is for 4 bands
</pre><p>if the user doesn't put anything in for band 3 i want the button to go through the calculations for 4 bands.</p><p>the band tolerance isnt in the equations because i want it to be displayed separately.</p>braedon marshhttps://au.mathworks.com/matlabcentral/profile/authors/8696763-braedon-marshtag:au.mathworks.com,2005:Question/926342013-01-03T19:04:00Z2018-04-23T02:48:12ZWhy do I get a connection error when installing or activating MATLAB or another MathWorks product?<p>I get an error that I cannot connect to MathWorks when running the MATLAB installer or the activation client. However, I can access the website. Why can't the activation client connect to the MathWorks?</p>MathWorks Support Teamhttps://au.mathworks.com/matlabcentral/profile/authors/4622813-mathworks-support-teamtag:au.mathworks.com,2005:Question/3964242018-04-21T08:56:35Z2018-04-23T02:34:56Zneed to synchronize two figures in matlab gui<p>I want to synchronise two figures in separate windows. The example code is given below.
Please can someone write a code for eme as I have just started using MATLAB GUI.</p><pre> im = imread (ImageA.jpg)
figure (1);
imagesc(im)
im1 =in2bw(im);
figure (2);
imagesc(im1)</pre>Aashhttps://au.mathworks.com/matlabcentral/profile/authors/10619661-aash