3D surf issue
1 回表示 (過去 30 日間)
古いコメントを表示
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)
0 件のコメント
採用された回答
Rik
2020 年 8 月 5 日
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 件のコメント
Rik
2020 年 8 月 5 日
- Yes. You can read the documentation for meshgrid and ndgrid for all available options.
- 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)
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!