How to edit each matrices in a cell?

1 回表示 (過去 30 日間)
Daniel Holden
Daniel Holden 2022 年 12 月 21 日
コメント済み: Daniel Holden 2022 年 12 月 22 日
Hello,
I have a 50x27 matrix that contains values between 0 and 55. I have been trying to create seperate matrices dependant on intervals of the matrix values. For example, I want to create matrix A that contains all the values between 0 and 5. Then matrix B that contains values between 5 and 10. Matrix C between 10 and 15...and so on. I have started the code below. NTG_MeanEmpty is a 50x27 matrix with values between 0 and 55.
L1 = 0:5:50;
L2 = 5:5:55;
n = 10;
Analysis = cell(n, 1);
for k = 1:n;
for m = 1:10;
for i = 1:50;
for j = 1:27;
if NTG_MeanEmpty(i,j) >= L1(1,m) & NTG_MeanEmpty(i,j) < L2(1,m);
Analysis{k,1}(i,j) = 1;
else Analysis{k,1}(i,j) = 0;
end
end
end
end
end
When I run the code it seems that the matrices contained within the 10x1 cell are not populated with any data. Please could you advise on any errors in this code, or suggest an alternative method?
Thank you.

採用された回答

Jan
Jan 2022 年 12 月 21 日
L1 = 0:5:50;
L2 = 5:5:55; % By the way, these are 11 values, not 10
NTG_MeanEmpty = randi([0, 55], 50, 27);
n = 11;
Analysis = cell(n, 1);
for k = 1:n
m = (NTG_MeanEmpty >= L1(k) & NTG_MeanEmpty < L2(k));
Analysis{k} = m; % Perhaps
% Or:
% tmp = zeros(50, 27);
% tmp(m) = NTG_MeanEmpty(m);
% Analysis{k} = tmp;
end
  1 件のコメント
Daniel Holden
Daniel Holden 2022 年 12 月 22 日
That worked! Thank you very much! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by