Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Need help on my for loop

조회 수: 1 (최근 30일)
adi kul
adi kul 2015년 5월 29일
마감: MATLAB Answer Bot 2021년 8월 20일
I am having a for loop which is a part of my script. There are 100 mat files in a folder which I am analyzing. Now in each file there is a variable "para" in which I am interested in. This variable is a 200x1 matrix and contains many different values. So i am interested in max and min of it.
Now I want to skip the values after calculation which are greater than 40 and to convert them to 20 and then plot.
So here is my code:
for i = 1:100
load(matFiles(i).name)
x(i)=max(para)-min(para)+1;
if x(k)>70,
x(k)=20;
end
plot(i, x(i), '.')
grid on
title('X')
xlabel('Mat file number');
ylabel('Para');
if i==1,
hold on
end
end
Can you tell me if I am doing it correctly? If not please let me know the correction.
also I got following command from one of my previous question
if i==1,
hold on
end
What is the logic behind this? I mean what it actually do?

답변 (1개)

Nobel Mondal
Nobel Mondal 2015년 5월 29일
편집: Nobel Mondal 2015년 5월 29일
Isn't there a mix-up between 'i' and 'k' index?
Also, you could use 'hold on' before starting the loop and avoid the condition check for each iteration. 'hold on' essentially lets you plot multiple data series in the same figure - by retaining the previous plot(s) while adding the latest one. Here is the matlab documentation: hold on off

이 질문은 마감되었습니다.

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by