Clear Filters
Clear Filters

How can I find midpoint in a structure of rows?

2 views (last 30 days)
Hello everyone,
I am trying to find every midpoint value between the min and max points that is in a row within a sturcture of rows.
Lumbar.Lift.AllMin = min(lumbar_lift,[],2);
Lumbar.Lift.AllMax = max(lumbar_lift,[],2);
This has worked with me so far. However, when I use the code below, it gives me weird values that are definetely not between the these values:
Lumbar.Lift.Allmid = min(abs(lumbar_lift-((Lumbar.Lift.AllMax + Lumbar.Lift.AllMin))/2),[],2);
your help is appirciated

Accepted Answer

Chunru
Chunru on 26 Jun 2021
a = randn(3, 10);
[nrows, ncols] = size(a);
[amin, imin] = min(a, [], 2)
amin = 3×1
-1.4505 -1.8692 -2.4076
imin = 3×1
9 2 7
[amax, imax] = max(a, [], 2)
amax = 3×1
1.8287 1.0523 0.6824
imax = 3×1
8 5 10
amed = median(a, 2)
amed = 3×1
0.5678 -0.3628 -0.6928
% mid points
for i=1:nrows
[~, imid] = min(abs(a(i, :)-(amin(i) + amax(i))/2)); % Get the index that coloset to the "mid point"
amid(i, 1) = a(i, imid);
end
amid
amid = 3×1
0.1543 -0.6789 -0.7695
  1 Comment
Abbas Alali
Abbas Alali on 27 Jun 2021
Thank you, this has worked with me. but it gave me the values in rows and I wanted them in coumns. I tried using the transpose function, A.', A' , but non of these have worked with me. Any sugesstion? Thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!