How do i evaluate a matrix in row by row case?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The data set contains values that fall within the two if statemet ranges. What i would like to do is that, execute each value separatetly. so for example if a value in row 3 column 1 falls within the first if statemet range then that gets executed and if the value in row 4 column 1 falls in the second if statemnt range that also gets executed. essentially i want to look at the data in a row by row case and keep the values in separate tables for each columns.
If there is another way of doing this please share.
Testdata;
n = 0;
Dist_type = {'Kernel', 'Gamma', 'Normal','Weibull'};
for j = 1 : numel(Dist_type)
if Testdata(Testdata(:,j) > 11.23 & Testdata(:,j) < 11.19) & (n == ~ 1)
%.....
n = 1;
t1 = table(Testdata(Testdata(:,j) > 11.23 & Testdata(:,j) < 11.19))
elseif Testdata(Testdata(:,j) > 11.28 & Testdata(:,j) < 11.33) & (n == ~ -1)
% .......
n = -1;
t2 = table(Testdata(Testdata(:,j) > 11.28 & Testdata(:,j) < 11.33))
else
n = 0;
end
end
0 commentaires
Réponse acceptée
Voss
le 10 Déc 2021
Modifié(e) : Voss
le 10 Déc 2021
Maybe something like this is what you want:
Dist_type = {'Kernel', 'Gamma', 'Normal','Weibull'};
for j = 1 : numel(Dist_type)
% Make two tables of the values in the jth column of Testdata that are
% within the two ranges:
% (Note that the first range as initially written would always contain
% no data, so I switched it around.)
t1 = table(Testdata(Testdata(:,j) > 11.19 & Testdata(:,j) < 11.23,j));
t2 = table(Testdata(Testdata(:,j) > 11.28 & Testdata(:,j) < 11.33,j));
% Do something with the tables
end
If you really want to go row-by-row, you can do that by adding a second nested for loop, but the code was already essentially operating on all rows at once.
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!