How can I fined min value in each row matrix that in cell?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
how can I fined min value in each row matrix that in cell?
6×1 cell array:
{15×15 cell} distance of special Coordinate pixels in image 1
{22×22 cell} distance of for special Coordinate pixels in image 2
{22×22 cell} distance of for special Coordinate pixels in image 3
{24×24 cell} distance of for special Coordinate pixels in image 4
{35×35 cell} distance of for special Coordinate pixels in image 5
{47×47 cell} distance of for special Coordinate pixels in image 6
I have error in last line.
I want fined closed and farest distance in image.
vecPoint{i}=[x1{i},y1{i}];
[m{i} n{i}] = size(vecPoint{i});
n{i} = m{i};
Dist{i}={};
for ii = 2 : m{i}
for jj = 2 : n{i}
Dist{jj,ii} = sqrt((vecPoint{i}(ii, 1) - vecPoint{i}(jj, 1)) ^ 2 + ...
(vecPoint{i}(ii, 2) - vecPoint{i}(jj, 2)) ^ 2);
Diss{jj,ii}=1./Dist{jj,ii};
end
end
MD(i)={(Dist)};
inverseDistances(i)={(Diss)};
% minsPerRow(i) = min(inverseDistances{i}, [], 2); % error in this LINE
6 Commenti
Stephen23
il 31 Dic 2019
Modificato: Stephen23
il 31 Dic 2019
By using nested cell arrays you are forcing yourself into writing much more complex code.
It appears that your nested cell arrays contain only scalars and empty arrays: if you replaced the empty arrays with NaN and then converted those nested cell arrays to numeric arrays (e.g. cell2mat) then your could could be simplified, e.g. the distance calculation can be vectorized:
and then your min call would actually work. Calculating the minimum of a cell array of scalar numerics is certainly possible (e.g. using a loop), but I wouldn't bother when using basic numeric arrays makes it so trivial. Calculating the distances between scalars in a cell array of scalar numerics is certainly possible (e.g. you used a double loop), but I would not bother when using numeric arrays makes it much easier (hint: vectorization).
As a general rule, store your data in the simplest array class possible. By using a more complex container class (the nested cell arrays) instead of a basic numeric array you just made accessing and processing your data much more complex.
Basically your code would be much simpler if you had this (and so far you have not shown or explained any reason why you cannot do this):
A = {[15x15 numeric array]; [22x22 numeric array]; ... }
Risposte (0)
Vedere anche
Categorie
Scopri di più su Feature Detection and Extraction in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!