Why the increment of plot not working ?

I don;t know where the error is as instead of 6 figures I get 36 figures as its a 2 for loops ,how to combine these 2 varying for loop results into one.I want to plot both the varying i and S values in 6 figures where the code works well when only i is checked and when I add k it goes to 36 ??
A = [125,25];
S(:,1) = [ 160 195 230 90 55 20];
S(:,2)= [ 25 25 25 25 25 25 ];
for i=[57 81 111 58 81 111]
for k = 1: 1:length(S)
figure('Position',[392,345,441,421]);
surf(Data(:,:,i)); shading interp; view(2); % couldn;t add data as its a big file
hold on
plot(S(k,1),S(k,2),'r.'); % sensor
hold on
plot(A(1),A(2),'k.') % actuator
colormap('summer')
axis square
xlabel('Length (cm)','fontweight','bold');
ylabel('Width (cm)','fontweight','bold');
xlim([0 250])
ylim([0 250])
end
end

 Réponse acceptée

infinity
infinity le 26 Juin 2019
Hello,
You shoul try to put
figure('Position',[392,345,441,421]);
surf(Data(:,:,i)); shading interp; view(2); % couldn;t add data as its a big file
hold on
outsite the loop of "k"
Check does it work or not.

7 commentaires

Ramesh Bala
Ramesh Bala le 26 Juin 2019
Hi Trung
You mean like this ??
A = [125,25];
S (:, 1) = [160 195 230 90 55 20];
S (:, 2) = [25 25 25 25 25 25];
for i = [57 81 111 58 81 111]
for k = 1: 1: length (S)
plot (S (k, 1), S (k, 2), 'r.' ); % sensor
hold on
plot (A (1), A (2), 'k.' ) % actuator
end
figure ( 'position' , [392,345,441,421]);
surf (Data (:,:, i)); shading interp ; view (2); % couldn; t add data as its a big file
hold on
colormap ( 'summer' )
axis square
xlabel ( 'Length (cm)' , 'fontweight' , 'bold' );
ylabel ( 'Width (cm)' , 'fontweight' , 'bold' );
xlim ([0 250])
ylim ([0 250])
end
But still it plots all the values of S in the same figure ,instead of plotting each value of S in each figure
Hello,
I mean you could try like this
for i=[57 81 111 58 81 111]
figure('Position',[392,345,441,421]);
surf(Data(:,:,i)); shading interp; view(2);
hold on
for k = 1: 1:length(S)
plot(S(k,1),S(k,2),'r.'); % sensor
hold on
plot(A(1),A(2),'k.') % actuator
end
colormap('summer')
axis square
xlabel('Length (cm)','fontweight','bold');
ylabel('Width (cm)','fontweight','bold');
xlim([0 250])
ylim([0 250])
hold off
end
Now, it should plot 6 figures with regard to the loop "i".
Ramesh Bala
Ramesh Bala le 26 Juin 2019
Thanks indeed it plots 6 figures with S,A values.But all the S values are present in all figures.
Can it be possible that with the k loop iteration S(1,1),S(1,2) in figure one and then S(k,1),S(k,2) goes on in another figures till 6 ?
Now it plots all S values in all 6 figures
Hello,
You could you "if" to plot S(1,1) and S(1,2) in figure 1, for example,
for k = 1: 1:length(S)
if (i == 1)
plot(S(1,1),S(1,2),'r.'); % sensor
else
plot(S(k,1),S(k,2),'r.'); % sensor
end
hold on
plot(A(1),A(2),'k.') % actuator
end
Is it what you want?
Ramesh Bala
Ramesh Bala le 26 Juin 2019
Modifié(e) : Ramesh Bala le 26 Juin 2019
No , I have added S(1,1) to give an example.But I want S(k,1),S(k,2) in incremental value in the 6 figures
S(1,1),S(1,2) in figure 1
S(2,1),S(2,2) in figure 2
S(3,1),S(3,2) in figure 3 and so on
Now the present code puts all the S in all the figures
Ok, I get your point. So you don't need to use loop "k" and we could use another variable "count" like in this code
count = 0;
for i=[57 81 111 58 81 111]
figure('Position',[392,345,441,421]);
surf(Data(:,:,i)); shading interp; view(2);
hold on
count = count + 1;
plot(S(count,1),S(count,2),'r.'); % sensor
hold on
plot(A(1),A(2),'k.') % actuator
colormap('summer')
axis square
xlabel('Length (cm)','fontweight','bold');
ylabel('Width (cm)','fontweight','bold');
xlim([0 250])
ylim([0 250])
hold off
end
I hope it may help.
Ramesh Bala
Ramesh Bala le 26 Juin 2019
yeah it works ! thanks :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by