How to save each loop ieration for creating a surf

Hello everyone,
I'm new to matlab and I`m working on the following code: h0 = ecv(0.7:0.05:1); h1 = ecv(0.7:0.05:1); FN = zeros(size1(h0),size1(h1),3); FP = zeros(size1(h0),size1(h1),3); ... for k=1:3 ... surf(h0, h1, FP-FN);
continue;
end
The code is long and contains a lot of other functions, that`s why I have replaced irrelevant pieces with ... The question is the following: The loop for k=1:3 generates 3 different values of FP. I need the results of all the loops in 3 different surface plots. Matlab shows an error by using the function surf everytime, because data dimensions must agree. I don't know how to fix the problem, tried many options, but I don't get it...
thank you much for your help!!

Answers (1)

I'm not sure what functions or variables ecv and size1 are, but maybe the following bit of code can be a useful reference (note FN and FP are 2D, and notice the order of the first two inputs to surf()):
h0 = 0.7:0.05:1;
h1 = 0.7:0.05:1.1;
FN = zeros(numel(h0),numel(h1));
FP = zeros(numel(h0),numel(h1));
for k=1:3
surf(h1, h0, FP-FN);
hold on
FP = FP+0.2; % make the surfaces different
end
Or maybe something like this (with 3D FN and FP) is what you mean to do:
figure();
h0 = 0.7:0.05:1;
h1 = 0.7:0.05:1.1;
FN = zeros(numel(h0),numel(h1),3);
FP = zeros(numel(h0),numel(h1),3);
for k=1:3
surf(h1, h0, FP(:,:,k)-FN(:,:,k) + 10*k); % + 10*k to make the surfaces different
hold on
end

1 Comment

Hello,
my problem is, i want to draw a new plot for each loop. But i can't get it to do that.
Any advice?

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 22 Jan 2018

Commented:

on 25 Jun 2023

Community Treasure Hunt

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

Start Hunting!