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!
