3D surf issue

1 vue (au cours des 30 derniers jours)
Andrew
Andrew le 4 Août 2020
Commenté : Andrew le 5 Août 2020
Good day,
I'm hawing a issue with 3D, I hawe to make that "Z would be a matrix, not a scalar or vector". Pleas give mea a hint how to acheve it.
x=0:100:50000;
y=x;
inc=(x+y)/2;
br_lim=[9408 14532 57051 270500];
for v1=1:length(inc)
y(v1)=(inc(v1)-br_lim(1,1))/10000;
g(v1)=(inc(v1)-br_lim(1,2))/10000;
if inc(v1)<br_lim(1,1)
Z(v1)=0;
elseif inc(v1)>=br_lim(1,1) && inc(v1)<br_lim(1,2)
Z(v1)=(972.87.*y(v1)+1400).*y(v1);
elseif inc(v1)>=br_lim(1,2) && inc(v1)<br_lim(1,3)
Z(v1)=(212.02.*g(v1)+2397).*g(v1)+972.79;
elseif inc(v1)>=br_lim(1,3) && inc(v1)<br_lim(1,4)
Z(v1)=.42*inc(v1)-8963.74;
else inc(v1)>=br_lim(1,4);
Z(v1)=.45*inc(v1)-17078.74;
end
end
[X,Y]=meshgrid(x,y);
figure
surf(X,Y,Z)

Réponse acceptée

Rik
Rik le 5 Août 2020
You are only filling a vector of Z, not the entire plane. Make sure you have a Z value for every value of X and Y. If you post (a description of) the function you're trying to implement, we can help you make a vectorized solution. Something like the code below.
[X,Y]=meshgrid(0:100:50000);
Z=zeros(size(X));
inc=(X+Y)/2;
y=(inc-br_lim(1,1))/10000;
g=(inc-br_lim(1,2))/10000;
br_lim=[9408 14532 57051 270500];
L= inc<br_lim(1) ;
Z(L)=0;
L= inc>=br_lim(1) & inc<br_lim(2) ;
Z(L)=___
%etc
  3 commentaires
Rik
Rik le 5 Août 2020
  1. Yes. You can read the documentation for meshgrid and ndgrid for all available options.
  2. L is a logical array (hence the name). It has the same size as Z. You will have to produce an output with the number of elements equal to the number of true elements in L. I would suggest experimenting with a small array to make sure you understand it.
[X,Y]=meshgrid(linspace(0,2*pi,100));
Z=zeros(size(X));
L= sin(X)>0 | cos(Y)>0 ;
Z(L)=sin(X(L))+sin(Y(L));
surf(X,Y,Z)
Andrew
Andrew le 5 Août 2020
Thank You once more.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Sparse Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by