Filter löschen
Filter löschen

Subplot graphs that I saved in a line

3 Ansichten (letzte 30 Tage)
Tiago Dias
Tiago Dias am 8 Mär. 2018
Beantwortet: Jan am 10 Mär. 2018
Hello, I made 2 functions to make graphs with the properties I want, instead of making it on the script.
for j = 1:2
out_1(j) = grafico('1',tempo(:,j),variavel_original(:,j),titulo{j},titulo1{j},titulo{j},var_original{j});
end
for j = 1:2
out_2(j) = grafico2('2',tempo(:,j),variavel_limpos(:,j),titulo{j},titulo1{j},titulo{j},var_limpos{j});
end
My function grafico has 5 data inputs, and '1', is the type of graph I want, for '1' he does grafico1, for '2' he does grafico2
function out = grafico(tipo,X,Y,eixoY,titulo,titulo2,legenda);
% tipo de gráfico
options = [{'1'};{'2'}];
if isempty(strmatch(lower(tipo),lower(options),'exact'))
errordlg([{'O tipo de gráfico especificado não existe!'};{' '};{'Ver função -> gráfico'}] ,'Erro de tipo de gráfico')
out = [];
return
end
switch tipo
case '1'
out = grafico1(X,Y,eixoY,titulo,titulo2,legenda);
case '2'
out = grafico2(X,Y,eixoY,titulo,titulo2,legenda);
end
OBJECTIVE Make a subplot of out_1 in subplot(2,1,1) and out_2 in subplot(2,1,2), in the same way, i wrote grafico1 and grafico2, I tried to make a grafico3, but the problem is that now I got 10 inputs and in the script when I do out_3 = grafico('10 inputs') it gives me an error because grafico only allows 5 inputs.
How can I solve this problem?
I tried in the script something like this bot obviously didnt work xD
for j = 1:2
subplot(2,1,1)
out_1(j);
subplot(2,1,2)
out_2(j);
  4 Kommentare
Jan
Jan am 9 Mär. 2018
out_1 and out_2 contain handles of line objects, which have been created by plot(). On one hand "out_1" is a bad name, because it does not help to understand, what the data are. On the other hand it is still not clear, what the intention of the shown code is:
for j = 1:2
subplot(2,1,1)
out_1(j);
subplot(2,1,2)
out_2(j);
It is not useful to repeatedly post code, which does not do, what you want. I cannot follow your explanations also. A bold guess is that you want to use copyobj to copy the line with the handle out_1(j) to the axes created by subplot(2,1,1). But then it would be much easier to plot the line in the wanted axes directly.
for j=2 -> i want a subplot with figure 2 and figure 4
You cannot create a subplot "with" a figure. A subplot is an axes object, which is always a child of a figure. So what does this mean?
I assume this is a problem of communication only.
Tiago Dias
Tiago Dias am 9 Mär. 2018
Bearbeitet: Tiago Dias am 9 Mär. 2018
i wll try to explain agian, i got 4 plots that i created by the function i created.
Plot 1 and 3, are form variable 1. Plot 2 and 4 are from variable 2,
So the objective here is to place plot 1 in subplot(2,1,1) and plot 3 in subplot(2,1,2) so in figure i get the 2 plots form variable1.
And in another figure, the graph 2 in subplot(2,1,1) and graph 4 in subplot(2,1,2).
But i have no idea how to "merge" the graphs I want in a figure, or if it is even possible to do that.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 10 Mär. 2018
I still do not get it. Perhaps you mean:
Fig1H = figure;
Fig2H = figure;
suplot(1,2,1, 'Parent', Fig1H);
plot(1:10, rand(1:10));
hold('on');
suplot(1,2,2, 'Parent', Fig2H);
plot(1:10, rand(1:10));
hold('on');
pause(1); % Just for demonstration
suplot(1,2,1, 'Parent', Fig1H);
plot(1:10, rand(1:10));
% Now the first plot is not overwritten due to "hold on"
I'd prefer an equivalent approach:
Fig1H = figure;
Fig2H = figure;
Axes11H = suplot(1,2,1, 'Parent', Fig1H, 'NextPlot', 'add');
Axes22H = suplot(1,2,12 'Parent', Fig2H, 'NextPlot', 'add');
% And the same for Axes12H and Axes21H...
plot(Axes11H, 1:10, rand(1:10), 'r');
plot(Axes22H, 1:10, rand(1:10), 'g');
plot(Axes11H, 1:10, rand(1:10), 'b');
plot(Axes22H, 1:10, rand(1:10), 'c');
Setting the property 'NextPlot' to 'add' is equivalent to hold('on'). Afterwards new plot commands are added instead of replacing the former objects.
I'm not sure if this is what you call "merge graphs". If not please try to explain the problem again. I do not understand if "i got 4 plots that i created by the function i created" is a fixed part of the problem. Is this part of the code fixed and you need an indirect and complicated method to copy the contents of the axes objects, or would a simple method to create the plots directly where they are wanted solve your problem already?

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by