フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

trouble with loops need help

1 回表示 (過去 30 日間)
Raul Castillo
Raul Castillo 2019 年 10 月 28 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
hi if i have an array with [1 2 3 4] and i wanted to associate 1 with 20, 2 with 30, 3 with 40 and so on how would i do that?
i know that i will start with something like this
if array = 1

回答 (2 件)

Star Strider
Star Strider 2019 年 10 月 28 日
I am not certain what result you want.
One approach:
array = [1 2 3 4];
target = [20 30 40 50];
Mapfcn = @(idx) target(array(idx));
Out = Mapfcn(array == 3)
Experiment to get your desired result.
  1 件のコメント
Raul Castillo
Raul Castillo 2019 年 10 月 28 日
sorry if i wasnt clear enough so form my array lets say s= [1 2 3 4 1 2 3 4 ]
and i want to assign 1=20 2=30 3=50 4=120 so that my new array would now be [20 30 50 120 20 30 50 120] do you get what i mean now?

ME
ME 2019 年 10 月 29 日
As in your previous question, you can use the following bit of code. I have also updated the error in my answer to your previous question.
for i=1:numel(s)
if(s(i)==1)
s(i)=20;
elseif(s(i)==2)
s(i)=30;
elseif(s(i)==3)
s(i)=50;
elseif(s(i)==4)
s(i)=120;
end
end

この質問は閉じられています。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by