필터 지우기
필터 지우기

Surf Plot using loops- Z must be a matrix, not a scalar or vector.

조회 수: 1 (최근 30일)
Fabricio Pena
Fabricio Pena 2017년 6월 20일
답변: Mechrod 2017년 6월 29일
Hello everyone,
I'm trying to plot a surface with the following code, but I keep getting this error. I don't know how to solve this, could someone help me?
Thanks in advance.
clear all;
% Welding parameters
%----------------------------
U = 28; %Voltage (V)
I = 260; %Current (A)
n = 0.9; %Efficiency
Q = U*I*n;
% Goldak Double-ellipsoid
%------------------------
a = 5;
b = 6;
C1 = 5;
C2 = 20;
FF = 0.6;
FR = 1.4;
x = [-10:.2:10];
y= 0;
for z = -15:.05:15
if z < 0
C = C1;
F = FF;
else
C = C2;
F = FR;
end
end
[xx,zz] = meshgrid(x,z);
A = ((6*sqrt(3)*F*Q)/(a*b*C*pi*sqrt(pi)));
B = exp(-3*(xx.^2/a.^2)).*exp(-3*(zz.^2/C.^2));
q = A*B;
surf (xx,zz,q)
Error using surf (line 57)
Z must be a matrix, not a scalar or vector.
Error in Goldak2 (line 34)
surf (xx,zz,q)
  댓글 수: 1
KSSV
KSSV 2017년 6월 20일
In your code z is a scalar, to use surf after meshgrid z should be matrix and a vector respectively.

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

채택된 답변

David Goodmanson
David Goodmanson 2017년 6월 20일
편집: David Goodmanson 2017년 6월 20일
Hi Fabricio, the z vector does not survive (except for its last value) after the for loop. z is a scalar at that point. So you need to do something like
z = -15:.05:15;
for z1 = z
if z1 < 0
C = C1;
F = FF;
else
C = C2;
F = FR;
end
end
[xx,zz] = meshgrid(x,z);
If you change the z spacing to something like .2 instead of .05, the plot is easier to see.

추가 답변 (1개)

Mechrod
Mechrod 2017년 6월 29일
Do you have a picture of what you are trying plot? So we now what are the dimensions a, b, c1, c2 and etc.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by