How to edit each matrices in a cell?

1 Ansicht (letzte 30 Tage)
Daniel Holden
Daniel Holden am 21 Dez. 2022
Kommentiert: Daniel Holden am 22 Dez. 2022
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.

Akzeptierte Antwort

Jan
Jan am 21 Dez. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by