Iterate script many times for different database and compare results

Hi,
Excuse me for my English, I don’t speak English very well so probably I don’t explain well my problem. I add an image to simplify my problem explanation.
I have to run a script many times (for each iteration the dimensions of my interest variables change). This script is the same but the data’s dimensions on which it’s based change. The different data correspond to two scenarios and I need to replace each scenario for two constant values and I need to compare them.
So finally I need to compare the different scenarios for different iterations.
To compare my interest variables I need to display plot and tables.
Then I think to save the result for next elaborations.
Could someone help me?
Thank you

9 Comments

Essentially, start at the case of one scenario for one iteration and code it. Just be sure to use generalized variable names and functions that can be called for the various scenarios to come.
Then, wrap that in a loop based on the number of cases within a scenario, saving the results in either structures or cell arrays to account for the size differences. You'll have to decide what it is that a "comparison" really means for such cases -- plots are easy; numeric tests may be more of an issue depending on what you're looking at for results.
Once you've got that down, then you can simply add another looping construct over the scenarios. It all sounds more complicated than it likely is given the ease with which Matlab handles reallocation of memory and the difference in types that can be held in cell arrays almost transparently.
Hi, thank you for the advices.
I have solved the problem.
I have this situation (script) whit many correlated scripts:
clear all
close all
clc
first_script % I call the first script
second_script % I call the second script. It’s a script that builds a matrix of random values and each row represent a scenario.
for i=1:N %N represent the number of iterations and it is also the rows’ number of the precedent matrix
third_script % I call the third script
end
% Now I disp and figure the results of the N iteration of the third script
If I would like to iterate the third script 2*N times, one for a constant value and the second for an other constant value, how I can display variables and plot figures to compare the different results changing the constant value? Maybe plotting in subplot?
If I would like to have all variables created by the third script in the workspace (i.e. number_of_cars_1 and number_of_cars_2, where number_of_cars could be vector or matrix with dimensions depending by number of iterations and subscripts 1 and 2 correspond to a constant's value or another) How I could do it?
Thank you.
first_script
second_script
for i=1:N
third_script
...number_of_cars could be vector or matrix with dimensions depending by number of iterations and subscripts 1 and 2...
Use a cell array would seem to be a reasonable solution altho you could also look at a dynamically-named structure.
See the following link on how to avoid creating variable names of the type you're using above--
Thank you, I've solved creating a cell array.
Now I am focussing on the graphs.
As you see in the img I have the same legend for the four subplot, how I can position it only once outside the subplot? (iterazione means iteration).
Thank you so much
Don't call legend each time in the loop, instead wait until after the subplots are finished and then use the form that includes the handle to one of the axes (likely the 2nd would be a good candidate at the upper RH corner, I'm guessing). Then try
hL=legend(hA(2), ..., 'BestOutside');
and see if that suits. It's quite a large legend box so you may decide it's better to reduce the size of the axes a little to make a little room outside. That's the 'position' property of the axes.
I have this situation:
for i=1:N txt{i}=['iteration' num2str(i)]; % I create the legend for subsequently subplots end
figure('units','normalized','outerposition',[0 0 1 1]); %figure a tutto schermo subplot(2,2,1) plot(x,risultati{2,1}{2,6}) legend(txt)
subplot(2,2,2) plot(x,risultati{3,1}{2,6}) legend(txt)
subplot(2,2,3) plot(x,risultati{2,1}{2,7}) legend(txt)
subplot(2,2,4) plot(x,risultati{3,1}{2,7}) legend(txt)
If I call legend only after subplot 2 my subplots change in dimensions and I don’t like this. I would like to have a legend outside subplots. I find this: http://www.mathworks.com/matlabcentral/newsreader/view_thread/150047
but I need that the string legend is ‘Iterazione1’, ‘Iterazione2’, ecc and not data.
Could you help me?
I've solved. I use:
sh=subplot(2,3,[3 6]); p=get(sh,'position'); lh=legend(sh,ph1); set(lh,'String',txt,'position',p); axis(sh,'off');
and it seems well, now I have only the problem for a common title for a figure with subplots.
Several threads on the subject recently...
There's a link to a File Exchange submission in my answer at the first link above -- I've not used it so no direct knowledge altho it's got good ratings...

Answers (0)

This question is closed.

Products

Asked:

on 29 May 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!