Group cell array and vector for "for loop and if statement"
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to choose submatrices from the table below.

For example, i want to choose first E01 values from column "Name" and after C2 MAX values form column "Case", and after Down values from column "Loc". I want to make that for every combination of this matrix. One of an example matrix should be as below:

How can i do this? After i can do this selection and get every combinations i will calculate some values from every seperate statement.
Who can help me ? :)
8 comentarios
Guillaume
el 1 de Mzo. de 2019
Ok, now it's clearer. Where does the Y come from? Is it just 1:10 in the order the values come in? Or the reverse of the numbers in the S column?
For E01-C2 MIN-Down, the values of S2 are:
-41.75
-40.97
-47.91
-53.96
-61.02
-71.36
-86.36
-104.51
-118.55
2.41
The maximum of that is 2.41. According to your rule, we would interpolate between 1.21 and 2.41. I presume that's not what you want.
Similarly, for E01-C2 MIN-Up, the values are
-47.4
-40.06
-47.82
-53.98
-61.06
-71.16
-85.82
-104.14
-117.93
-26.09
With maximum -26.09. So an interpolation between -13.05 and -26.09. Presumably not what you want.
Respuestas (2)
Andrei Bobrov
el 1 de Mzo. de 2019
mat.xlsx - file with your data
T = readtable('mat.xlsx');
[~,jj] = sortrows(T(:,2:4))
out = T(jj,:);
Guillaume
el 1 de Mzo. de 2019
I do not really understand your interpolation at all. I do not understand how your interpolated values go from 77.28 when half of max is 69.08 nor why 138 is repeated.
Anyway, here is some code to do part of what you want. You'll need to modify the interpolation code to do exactly what you want.
First, create a function to do the plotting for a group:
function groupplot(s2, name, casename, loc)
%s2: the value of column S2 for the group
%name: the name of the group. Will come as a cell array with all identical values
%casename: the case of the group. Will come as a cell array with all identical values
%loc: the loc of the group. Will come as a cell array with all identical values
[absmax, row] = max(abs(s2)); %find the absolute maximum and its location
sgn = sign(s2(row)); %sign of the maximum
s2interpolated = interp1(s2, s2, sgn * linspace(0.5*absmax, absmax, 10)); %not what you want but I don't understand what you want
figure;
plot(s2, 10:-1:1, s2interpolated, 10:-1:1);
legend('Original data', 'interpolated data');
title(sprintf('%s - %s - %s', name{1}, casename{1}, loc{1}));
end
and save that.
To apply this to your data:
data = readtable('data.xlsx');
rowfun(@groupplot, data, 'GroupingVariables', {'Name', 'Case', 'Loc'}, 'InputVariables', {'S2', 'Name', 'Case', 'Loc'}, 'NumOutputs', 0);
rowfun takes care of splitting the data into groups and calling the function for each group.
7 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


