Info

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

How to change valuo of variable with for loop ?

조회 수: 1 (최근 30일)
Muhammad Andi Yusran
Muhammad Andi Yusran 2020년 5월 5일
마감: MATLAB Answer Bot 2021년 8월 20일
I want to change my variable value. I have 204 value in my output variable. I want to change it to specified. if the value is 1, change to 'One'. if the value is 2, change to 'Two'. I try my code but the variable name wont looping. Please help me.
m = matfile('elm_output.mat');
output = m.output;
required = output(1:204);
for i = 1:length(required)
if required(i) == 1
lbl = 'One';
name = {lbl};
end
if required(i) == 2
lbl = 'Two';
name = {lbl};
end
end
  댓글 수: 1
Stephen23
Stephen23 2020년 5월 5일
편집: Stephen23 2020년 5월 5일
The MATLAB approach would be to use basic arrays and indexing, rather than loops and ifs:
C = {'one','two'};
name = C(required);

답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by