How Vectorize operation?
Show older comments
I need to put a marker, var flag_min_ce to the records that are smaller for a given variable, among the non-zero values, for a given i, for example in column 8, leaving the rest of rows i with 0, ... then must do the same with i = 2, ... works well for i = 1, but from then on he chooses the zeros My code is:
load('MS_Config.txt')
structureMS = {'Algoritmo', 'Imagen', 'proporcion', 'iteracion', 'bw',...
'delta_t', 'tiempo', 'CE', 'MCS', 'MCD', 'W', 'WSS', 'DI',...
'CH', 'DB', 'XB', 'Num_centros', 'Fecha'};
num_images = 32;
num_iterations = 14;
min_ce = [];
for i = 1:num_images
flag_min_ce = MS_Config((MS_Config(:,2) == i),8) == ...
min(MS_Config(MS_Config((MS_Config(:,2) == i),8) > 0, 8))
min_ce = [min_ce; flag_min_ce];
end
a = [min_ce MS_Config ];
6 Comments
dpb
on 19 May 2018
Better to explain the data structure and the desired result; providing a small example generally helps as well as attach enough data that somebody can use it for testing rather than trying to emulate the problem.
Image Analyst
on 19 May 2018
What does "put a marker to the records" mean? In column 8 you want to keep the zeros, but what do you want to other values to be? Unchanged? Something else? Do you just want a new logical vector like markers = column8 ~= 0???
Joffre
on 19 May 2018
Jan
on 19 May 2018
...but of the lowest value different from zero...
The lowest value of what? Please pos a relevant example.
Joffre
on 19 May 2018
Answers (1)
I cannot really follow your description. Do you want the lowest value for all elements of column 8, which have the same index in column 2?
What is the relation to the posted code? I guess MS_Config is the shown matrix?
Then:
zeroInC8 = (MS_Config(:, 8) == 0);
MS_Config(zeroInC8, 8) = Inf; % Hide the 0 values
Result = splitapply(@min, MS_Config(:, 8), MS_Config(:, 2))
2 Comments
Joffre
on 19 May 2018
Image Analyst
on 20 May 2018
He's done? But is your problem solved? You have not Accepted this answer, so is it still a problem? If not, please "Accept this answer", otherwise explain what problem(s) remain.
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!