How do i evaluate a matrix in row by row case?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Voss
2021-12-10
编辑:Voss
2021-12-10
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!