Fill a vector with specific values from a matrix

Hello, I'd like to identiy which values are greater than 4 in matrix "a" and fill those values into matrix "b". The code I tried was this, but it didn't work.
a=[1 4 23 5
5 2 7 8
3 4 6 3];
for i=1:size(a,1)
for j=1:size(a,2)
if a(i,j) > 4
b(:)=a(i,j)
end
end
end

 採用された回答

Stephen23
Stephen23 2021 年 11 月 6 日

1 投票

a = [1,4,23,5;5,2,7,8;3,4,6,3];
b = a(a>4)
b = 6×1
5 23 7 6 5 8

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeAdaptive Control についてさらに検索

製品

リリース

R2021b

質問済み:

2021 年 11 月 6 日

回答済み:

2021 年 11 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by