How Vectorize operation?
显示 更早的评论
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 个评论
dpb
2018-5-19
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
2018-5-19
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
2018-5-19
Jan
2018-5-19
...but of the lowest value different from zero...
The lowest value of what? Please pos a relevant example.
Joffre
2018-5-19
回答(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 个评论
Joffre
2018-5-19
Image Analyst
2018-5-20
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
