Why the increment of plot not working ?

1 回表示 (過去 30 日間)
Ramesh Bala
Ramesh Bala 2019 年 6 月 26 日
コメント済み: Ramesh Bala 2019 年 6 月 26 日
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

採用された回答

infinity
infinity 2019 年 6 月 26 日
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 件のコメント
infinity
infinity 2019 年 6 月 26 日
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 2019 年 6 月 26 日
yeah it works ! thanks :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by