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

采纳的回答

Voss
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.
  1 个评论
HabenG
HabenG 2021-12-10
编辑:HabenG 2021-12-10
I will try this and yes i really need to go row by row beause this is supposed to operate on a streaming data so i wont have a table or a set of data. The only other option i have is to make this work based on the last value that falls within any of those two statement....also thanks much

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by