How do I plot the different values in a for loop on the same plot? (confusing problem!)

3 views (last 30 days)
I am wanting to take axial cuts sweeping from right to left along the x co-ords -0.05 to -1.0 in -0.05 increments to get the force distribution between the upper and lower boundaries. As the shape I am taking the cuts through is roughly rectangular and sloping downwards from right to left (so a +ve gradient) the y co-ordinates are different (decrease) as you move to the left of the shape, so i normalized the coordinates so that they show as values between 0-100% of the shape boundary. This way all plots (at x=-0.05 to -1.0) should lie on top of each other but with different forces.
The problem I am having is that it is storing Ycut2, Ycut2_gap, Fcut2 as 1x23 matrices, where as I need them to be stored as that, but for every value of x i took the cut at (rather than just the last one or what ever it is storing).
I've attached what i have on it so far below:
--------------------------------------
X = 279x23 matrix (x co-ords [range from -2 to +2])
Y = 279x23 matrix (y co-ords [range from -2 to +2])
F = 279x23 matrix (force at x-y position [all +ve values])
--------------------------------------
for i = 1 : 23
for j = -0.05:-0.05:-1.0
Ycut2(i) = interp1(X(:,i),Y(:,i),j,'spline');
Fcut2(i) = interp1(X(:,i),F(:,i),j,'spline');
end
end
--
% normalizes co-ords so that it is between 0 - 100%
Ycut2_gap = max(Ycut2)-min(Ycut2);
for i = 1:23
Ycut2_range(i) = (Ycut2(:,i)-min(Ycut2)) / Ycut2_gap * 100;
end
--
figure
plot(Ycut2_range,Fcut2),axis image

Accepted Answer

Joseph Cheng
Joseph Cheng on 5 Aug 2014
If i read your desired result correctly the issue is here
for i = 1 : 23
for j = -0.05:-0.05:-1.0
Ycut2(i) = interp1(X(:,i),Y(:,i),j,'spline');
Fcut2(i) = interp1(X(:,i),F(:,i),j,'spline');
end
end
which you're overwriting your Ycut2 and Fcut2 everytime the j forloop occurs. you're not storing the values that are being generated. what you could do is:
slices = -0.05:-0.05:-1.0;
for i = 1 : 23
for j = 1:length(slices)
Ycut2(i,j) = interp1(X(:,i),Y(:,i),slices(j),'spline');
Fcut2(i,j) = interp1(X(:,i),F(:,i),slices(j),'spline');
end
end
which will get you all the values of F and Y along the different X points.
  3 Comments
Joseph Cheng
Joseph Cheng on 5 Aug 2014
check your dimensions of Ycut2 and what you're trying to do with your normilization. do you want it all to be normailized slice by slice or over the "image". from what i can see there is a dimension mismatch as min of Ycut2(:,i) min(Ycut2) and ycut_gap do no agree. as a simple example min(ycut2) is a 1xn matrix and Ycut2(:,i) is a m by 1. so the row columns doesn't match.
steven
steven on 6 Aug 2014
Thanks, finally figured it out. That section was a complete mess so re-wrote it. Thanks for your help on the first section though, much appreciated!

Sign in to comment.

More Answers (0)

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!