How extract the value in certain position for a loop in matlab?

3 ビュー (過去 30 日間)
DulceEien
DulceEien 2021 年 8 月 10 日
編集済み: DulceEien 2021 年 8 月 10 日
How can I the output in a vector, when I run it I'm getting a single number
ID =[2003;2201;3350;9123;8234;1234]
for i = 1:length(ID)
y(i) = num2str(ID)
out(i) = str2num(y(2))
end
I need the third position because that value will give me in another conditional the importance of that element
for i = 1:length(ID)
if out(i) == 0
EI(i) = 'Very high';
elseif out(i) == 1
EI(i) = 'High';
elseif out(i) == 2
EI(i) = 'Medium';
elseif out(i) == 3
EI(i)= 'Low';
end
end
I really appreciate your help

採用された回答

Dave B
Dave B 2021 年 8 月 10 日
I think what you're asking is for a vector with the second digit of the values in y?
Here's a fixed version of your code:
ID =[2003;2201;3350;9123;8234;1234];
for i = 1:length(ID)
y = num2str(ID(i));
out(i) = str2num(y(2));
end
disp(out)
0 2 3 1 2 2
Here's a better way:
out=double(extract(string(ID),2))';
disp(out)
0 2 3 1 2 2
  1 件のコメント
DulceEien
DulceEien 2021 年 8 月 10 日
編集済み: DulceEien 2021 年 8 月 10 日
than you so much for your answer, it works

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAI for Signals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by