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 个评论

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.
Ok, thanks for your attention, the relevant structure of the data is:
Algoritmo => algorithm of segmentation of image
Imagen => Matrix of image
Iteracion => Algorithm run
bw, delta_t => Parameters of the algorithm
CE, MCS, MCD, W, WSS, DI, CH, DB and XB => Clustering validation index
Num_centros => Number of centers obtained by executing the iteration in the algorithm.
It`s the more important.
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.
Thanks
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???
Marker or a flag to indicate that this row contains the best run of the algorithm for the image, I want to keep the values of column 8 and effectively add a new column as a logical marker, but of the lowest value different from zero.
...but of the lowest value different from zero...
The lowest value of what? Please pos a relevant example.
Ok, the lowest value different from zero for column 8 CVI = CE and for each imagen. In a similar way I will proceed for the other CVI, looking for the lower or higher value according to CVI is verifying, for the case of entropy, the lowest value is sought, see the image below.
Thanks

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2018-5-19
编辑:Jan 2018-5-19
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 个评论

Thank you, you helped me, I modified your code a bit and you're done.
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 的更多信息

标签

提问:

2018-5-18

Community Treasure Hunt

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

Start Hunting!

Translated by