Blank figure in MatLab [closed]

[This is my MatLab code and I am trying to take a plot of what I have done, but when I run the code the plots are all empty
Do you know how I can fix it?

clear
clc
steptime= 0.0001;
t=[10;10;10];

% position parameters
% p=[x_initial y_initial z_initial]
p_0= [0.999;0.999;0.999];
p_env=[1;1;1];
p_desire=[1.1;1.1;1.1];

% Parameters
m = 0.5;
K_E=1000;
K_V=5;
K_P=3;

k_e=K_E*eye(3);
k_v=K_V*eye(3);
k_p=K_P*eye(3);

f_e = (k_e*p_0) - (k_e*p_env);
sim('Force_Control_Finger')

subplot(2,1,1)
plot(t,p_0)
xlabel('time[s]')
ylabel('position')

subplot(2,1,2)
plot(t,f_e)
xlabel('time[s]')
ylabel('f_e[N]')

figure
plot(t,f_e)
xlabel('time[s]')
ylabel('f_e[N]')

• Are you expecting 1 or 2 figures from this code? – The Photon Jun 7 at 16:02
• yes two figures – Ha D Jun 7 at 16:02
• What have you done to debug so far? – Scott Seidman Jun 7 at 16:04
• I changed the time vector but it did not work. – Ha D Jun 7 at 16:05
• Look at the contents of each variable, and make sure you understand what is in each – Scott Seidman Jun 7 at 16:06

The problem is you are plotting a single point and equally multiple single points on top of each other. By default Matlab suppresses points which makes sense when you are doing a line plot of continually varying data but not so much when it is a single point

your time array is a 3 entry array of the same time, 10.

t=[10;10;10]

t =

10
10
10


Now if you make a slight edit to the plot command:

plot(t,p_0,'k*','MarkerSize',20)

ie plot in black, markers as an astrisk and make the marker large, this is what you have. You will have three stars over each other due to the same data being asked to be plotted, three times:

p_0

p_0 =

0.9990
0.9990
0.9990


How to fix? well what are you trying to do because this is doing exactly what it should but without additional info we can't help

--edit-- so I recreated your model and changed the key variables to single dimension

p_0= 0.999 p_env=1 p_desire=1.1

• Thanks a lot for your complete answer.I am trying to do force control for my finger robot, and it seems that the Simulink simulation does not work in matlab, cause when I do not define the t and f_e in matlab file , the code does not work and asks me to define these two. – Ha D Jun 7 at 17:08
• where is t being used in the simulink file? Typically there should be a Time vector produced by the simulink file. Likewise where is f_e being used in the model? a constant block? gain etc? what you should have is a to_workspace block to output the results of your time-varying simulation. Within Simulink, can you attach a scope to the node you are attempting to plot via matlab? – JonRB Jun 7 at 17:21
• I already added the snapshot of my Simulink simulation to my question. could you please take a look at it? – Ha D Jun 7 at 17:23
• I see you have attached the block overview in the original post. On the face of it, it looks valid. What doesn't make sense is why you said it complains if you don't pre-declare "t" since t is the output of the clock. What solver are you ussing? is it a continuous solver? this could be a refinement issue. Try putting a scope at the same places as those to_workspaces to see what they look like – JonRB Jun 7 at 17:23
• the solver is fixed-step type and ode5(Dormant_Prince) – Ha D Jun 7 at 17:28

Add figure to create a figure window before the subplots, you need to create two figure windows

 figure
subplot(2,1,1)


Your data is three points all in the same place so the first plot is probably not Change t to t = 1:3 Or t = [9;10;11]

• Hi, I wonder how this kind of a question is accepted as an EE.SE question? Some of my questions, which were far more related to EE w.r.t to this one to me, were labeled as off-topic before. – muyustan Jun 7 at 16:30
• you do not need to create two figure windows. The 1st plot command will create a figure, any additional figures to isolate plots will need figure called. The OP stated their intent is two figures and their code will do this (since there is an explicit call to figure later). Likewise a lack of a figure call does not answer why a plot window would be "blank". – JonRB Jun 7 at 16:58
• @muystan which questions? – Voltage Spike Jun 7 at 22:15