Surface Animation from For Loop Help

Hi, I am trying to create a surface that changes over time by using a for loop. I want this to be a plane surface that changes orientation by the values in the arrays I have set for x and y. I cannot seem to get an animation to be made after trying several techniques found online. Here is my current code, thanks in advance.
% Lat for test
x = [0 0.018000 0.0330 0.0410 0.0490 0.0550 0.0640 0.0760 0.0960];
% Long for test
y = [0 0.1520 0.20 0.180 0.1880 0.2270 0.2820 0.3380 0.3880];
g = 1;
Slope = [];
for i = 2:length(x) % Go through data one step at a time until through all data
% Slope must change each time with different x value
Slope(i) = (x(i) - x(i-1))/(y(i) - y(i-1));
end
ynew = Slope.*x;
for i = 1:length(Slope)
figure(1)
surf([x; x], [ynew(1,:); ynew(1,:)], [zeros(size(x)); ones(size(x))]); % Surface attempting to be moved
end

4 件のコメント

Image Analyst
Image Analyst 2021 年 11 月 21 日
You forgot to atach 'latlong.xlsx'. Also, when you're editing to attach that, highlight your code and click the Code icon to format it as code. I'll check back later.
Luke Malone
Luke Malone 2021 年 11 月 21 日
Hi, latlong.xlsx was just the data I was importing from. I was using the x and y as just a snippet from that data sheet for my testing purposes. I have removed import line to reduce any confusion. Thank you
Image Analyst
Image Analyst 2021 年 11 月 21 日
Luke, try to run the code before posting. We can't run that code. It gets to the time line and then says it doesn't know what T is.
Luke Malone
Luke Malone 2021 年 11 月 21 日
My bad, I didn't know that you could run the code in the browser, I just tested it here now and it seems to work.

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2021 年 11 月 21 日
編集済み: Image Analyst 2021 年 11 月 21 日

0 投票

In your loop, this does not change
[ynew(1,:); ynew(1,:)]
Nothing in that depends on "i" so your surface looks the same at every iteration.
And put in
drawnow;
pause(1);
at the end of your loop so you can see each individual surface.

2 件のコメント

Luke Malone
Luke Malone 2021 年 11 月 21 日
I tried using,
surf([x(i); x(i)], [ynew(i)(1,:); ynew(i)(1,:)], [zeros(size(x)); ones(size(x))]);
But this didn't work either. Where should I put the (i) dependecy?
Image Analyst
Image Analyst 2021 年 11 月 22 日
Do you actually HAVE a surface? Or just an x and y vector? You might need to make a surface with scatteredInterpolant before you can call surf. See attached demo.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeAnimation についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 11 月 21 日

コメント済み:

2021 年 11 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by