Hi, I have to plot curves "MSE" witch depend on 2 variables. Variable 1 : "pct=1:1:n" and variable 2 : "CR" .
But "CR" depends on two variables also:
"ptx=1:1:n" and "pct=1:1:n"
MSE=fct(CR,pct)
Here a simplification of the code:
for pct=1:1:n
for ptx=1:1:n
calculate CR(pct,ptx)
calculate MSE(pct,ptx)
end
end
I want to plot curves of "MSE" in function with "pct" and "CR" , it means ;
axis x : "pct"
axis y : "CR"
axis z : "MSE"
That is, a kind of succession of curves Thank you in advance

댓글 수: 4

Ameer Hamza
Ameer Hamza 2018년 6월 16일
편집: Ameer Hamza 2018년 6월 16일
Have you tried plot3()
plot3(pct, CR, MSE);
kortas manel
kortas manel 2018년 6월 16일
편집: kortas manel 2018년 6월 16일
MSE is a matrix of size (n*n)= (pct=1:1:n)*(ptx=1:1:n) CR is a matrix of size (n*n)= (pct=1:1:n)*(ptx=1:1:n)
When I tried : plot3(1:n, CR , MSE) , I obtained this
the curves that I want to get comes from this loop
for pct=1:n figure(pct) plot(CR(pct,:),MSE(pct,:)) end
But I want these curves in one graph positioned successively according to pct values
Ameer Hamza
Ameer Hamza 2018년 6월 16일
Your x variable is an n-element vector, whereas y and z are nxn matrices. And from your for loop example, it seems that you want several 2D plots. Can you show an example plot similar to what you are trying to draw?
kortas manel
kortas manel 2018년 6월 16일
Yes that's it, but I want them in the same graph so that the first curve containing MSE = fct (CR) put on the plane (y, z) intersects x axis at point pct = 1, the second curve containing MSE = fct (CR) put on the plane (y, z) cross section x at point pct = 2, etc.

댓글을 달려면 로그인하십시오.

 채택된 답변

Ameer Hamza
Ameer Hamza 2018년 6월 16일
편집: Ameer Hamza 2018년 6월 16일

0 개 추천

From your question description, it appears you want something like this
Here is a sample code with random values to generate this
n = 10;
x = 1:n; % 1 x n vector
y = repmat(1:n, n, 1); % n x n matrix
z = rand(n); % n x n matrix
plot3(1*ones(n,1), y(1, :), z(1, :)); % plot one line outside for loop to get the axes handle
ax = gca;
hold(ax);
grid on
xlabel('pct');
ylabel('CR');
zlabel('MSE');
for i=2:n
plot3(i*ones(n,1), y(i, :), z(i, :));
end

댓글 수: 2

kortas manel
kortas manel 2018년 6월 16일
That's what I need, thank you , just another point : when x=1:10 but y=repmat(1:9,10,1). It means y of size(10*9) also z is of size(10*9) it gives : Vectors must be the same length. Normally it should not be a problem as vectors y(i,:) and z(i,:) have the same length
In that case, you will also need to adjust the first input to plot3()
plot3(i*ones(9,1), y(i, :), z(i, :));
I guess this might be causing the issue.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Guillaume
Guillaume 2018년 6월 16일

0 개 추천

If your calculate functions can operate on matrices:
[pct, ptx] = ndgrid(n);
CR = yourcalculateCRfunction(pct, ptx);
MSE = yourcalculateMSEfunction(pct, ptx);
plot3(pct, CR, MSE);
Otherwise
[pct, ptx] = ndgrid(n);
CR = zeros(size(pct));
MSE = zeros(size(pct));
for i = 1:numel(pct)
CR(i) = yourcalculateCRfunction(pct(i), ptx(i));
MSE(i) = yourcalculateMSEfunction(pct(i), ptx(i));
end
plot3(pct, CR, MSE);

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2018년 6월 16일

댓글:

2018년 6월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by