How to edit each matrices in a cell?

1 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops 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