why would Matlab skip the loop??
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
I have a question that I can seem to wrap my head around,
I have created a gui that uses the unput from the user to run a script within the gui and later display the results to the user interface. What I dont understand is that everything is running ok until I choose one particular file. The interesting and mind boggling is that the script jumps a nested loop (whie this dosent happen for the other choices). I dont understand why this happens and cant find anything relavent on the internet. The script stand alone executes perfectly.
for i=2:length(Data_last_values)
for j=2:length(temp_nov)
if Data_last_values(i,4)>temp_nov(j,1) & Data_last_values(i,4)<temp_nov(j-1,1)
Data_last_values(i,9)=Data_last_values(i,3)+Q_leak_dot(j);
disp('gone through loop')
end
end
end
displayed above is the part of the nested loop that matlab chooses to skip. would any one know why this happens? below I present the gui script:
if not(isempty(cell2mat(z)))
run Daughter
assignin('base','avg',data(:,8))
axes(handles.axes1);
markerSize = 50;
scatter(Data_last_values(:,4),Data_last_values(:,9),markerSize,Data_last_values(:,5)) % -> volumetric mass flow is used in the color bar
colormap(jet(20));
h=colorbar;
xlabel('T_{water}[C]')
ylabel('Q_{out} [W]')
ylabel(h, 'Volumetric Flow [Lt/min]')
grid minor
myvar = evalin('base', 'avg');
y=line([0 max(Data_last_values(:,4))], [mean(myvar) mean(myvar)]);
xlim([0 max(Data_last_values(:,4))])
0 Commenti
Risposte (1)
Image Analyst
il 1 Set 2015
What is the value of temp_nov and length(temp_nov)? temp_nov seems to be a 2D array. Did you know that length gives the size of the longest dimension when passed a 2D array. What exactly were you hoping to get: the rows or columns?
Are you using the debugger? I don't mean the "debug by Answers forum" debugger, but the actual debugger where you can step through your program and see the values of variables and see what lines of code get executed? That is what everybody uses and will undoubtedly be your fastest way to a solution. http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
Also, the double for loop you say it skips is not even in the "gui script" code so I don't doubt that it doesn't get executed - it's not even there!
1 Commento
Guillaume
il 1 Set 2015
Modificato: Guillaume
il 1 Set 2015
In addition to IA's comments, how do you know that the loop is skipped? Since the message 'gone through loop' is in a if statement, if the if condition is never true, the message will never be displayed even though the code has gone through the loop.
Vedere anche
Categorie
Scopri di più su Title in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!