How can I fined min value in each row matrix that in cell?

1 view (last 30 days)
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 Comments
Stephen23
Stephen23 on 31 Dec 2019
Edited: Stephen23 on 31 Dec 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]; ... }
jenifer Ask
jenifer Ask on 31 Dec 2019
Edited: jenifer Ask on 2 Jan 2020
I want to find the farthest distances from the current point.
For example, the code I can use to calculate the distance farthest from the current point in an image is as follows.
I try to do this calculation for several images separately, But I can't

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!