How can I find midpoint in a structure of rows?

2 次查看(过去 30 天)
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

采纳的回答

Chunru
Chunru 2021-6-26
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 个评论
Abbas Alali
Abbas Alali 2021-6-27
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by