# plot and surf 3D graph

4 views (last 30 days)
siew chin cheu on 9 Nov 2011
Answered: VBBV on 29 Nov 2021
dear all, i am a new learner of matlab and was given a assignment to solve a matlab programming question. some errors occur and i unable to plot 3D graph. the error shown is as follow:
??? Error using ==> plot
Data may not have more than 2 dimensions
Error in ==> aaa at 28
subplot(2,2,1), plot(sseff);
the work that I did is as follow:
for Kp = 1:1:3
for tau = 1:1:3
for theta = 1:1:3
for lambda = 1:1:3
%Tuning the controller
Kc(Kp, tau, theta, lambda) = (2*tau+theta)/2*Kp*(lambda+theta);
taui(tau, theta)= tau+theta/2;
taud(tau, theta)= tau*theta/(2*tau+theta);
num = Kp;
den = [tau 1];
sp = 1;
[numCL,denCL]=cloop(Kc(Kp, tau, theta, lambda)*num*theta,den, -1);
t=0:0.01:5;
y = step(numCL, denCL,t);
sse = (sp - y);
ssef =sum(sse'*sse);
sseff(Kp, tau, theta, lambda) = ssef
end
end
end
end
subplot(2,2,1), plot(sseff);
title('Plot of SSE with multiple values of Tau')
ylabel('Sum of Square Error')
xlabel('Tdelay')
grid;
subplot(2,2,2), surf(sseff')
title('Plot of Sum of Square Error')
ylabel('Tau')
xlabel('Tdelay')
zlabel('Sum of Square Error')
subplot(2,2,3),plot(Kc)
title('Plot of Gain Kc')
xlabel('Tdelay')
ylabel('Sum of Square Error')
grid;
subplot(2,2,4),surf(Kc')
title('Plot of Kc with multiple values of Tau')
ylabel('Tau')
xlabel('Tdelay')
zlabel('Sum of Square Error')
so can anyone help me to find out what are the errors and the correct answers? thank you. My email address: siewchin0911@yahoo.com

Fangjun Jiang on 9 Nov 2011
The error message says it all. Data used in plot() may not have more than 2 dimensions. Your data sseff seems to have a dimension of 4.

VBBV on 29 Nov 2021
for Kp = 1:1:3
for tau = 1:1:3
for theta = 1:1:3
for lambda = 1:1:3
%Tuning the controller
Kc(Kp, tau, theta, lambda) = (2*tau+theta)/2*Kp*(lambda+theta);
taui(tau, theta)= tau+theta/2;
taud(tau, theta)= tau*theta/(2*tau+theta);
num = Kp;
den = [tau 1];
sp = 1;
[numCL,denCL]=cloop(Kc(Kp, tau, theta, lambda)*num*theta,den, -1);
t=0:0.01:5;
y = step(numCL, denCL,t);
Sse = (sp - y); % change variable name convention
ssef =sum(Sse'*Sse); % use a variable with non-standard function,
sseff(Kp, tau, theta, lambda) = ssef;
end
end
end
end
subplot(2,2,1), plot(sseff(1,:,2,1));
title('Plot of SSE with multiple values of Tau')
ylabel('Sum of Square Error')
xlabel('Tdelay')
grid;
subplot(2,2,2),
skx(:,:) = sseff(1,:,2,:);
surf(skx)
title('Plot of Sum of Square Error')
ylabel('Tau')
xlabel('Lambda')
zlabel('Sum of Square Error')
subplot(2,2,3),plot(Kc(1,:,2,1))
title('Plot of Gain Kc')
xlabel('Tdelay')
ylabel('Sum of Square Error')
grid;
subplot(2,2,4), kkx(:,:) = Kc(1,:,2,:); surf(kkx)
title('Plot of Kc with multiple values of Tau')
ylabel('Tau')
xlabel('Lambda')
zlabel('Sum of Square Error')
Use the specific variable ,dimension range to plot your results. From the axis labeling variables, you can select which one to plot.