Marking of different shapes, font, MATLAB size

I am trying to basically copy this chart for practice for my final output, but I don’t understand how to change the font, size or marking of the axis. Simply put, I need to accurately reproduce this graph from my code. I need the font to be a new Roman font and size 18 with a marker size size 8. How do I format the code in this? enter image description here

This is my code:

clear
clc

x = linspace(0,2);
y1 = sin(2*pi*x);
y2 = exp(-0.5*2*pi*x).*sin(2*pi*x);


figure
subplot(2,1,1);
hPlot1 = plot(x,y1,'rs');
ylabel('f(t)')
set(gca,'YLim',[-1 2],'YTick',-1:1:2,'XTick',0:.5:2)

subplot(2,1,2);
hPlot2 = plot(x,y2,'k*');
xlabel('Time(s)')
ylabel('g(t)')
set(gca,'YLim',[-0.2,0.6],'YTick',[-0.2,0,0.2,0.4,0.6],'XTick',0:.5:2)
+4
source share
2 answers

Replace xlabel('Time(s)')with:

xlabel('Time(s)','FontName','TimesNewRoman','FontSize',18)

and do the same for ylabel.

For marker size, replace hPlot1 = plot(x,y1,'rs');with

hPlot1 = plot(x,y1,'r-',x(1:5:end),y1(1:5:end),'ks','MarkerSize',8);

and the same for another chart.

, text, :

text(0.5,1.5,'Harmonic force f(t) = sin(\omega t)')

, , xlabel ylabel.

+3

:

%// x = linspace(0,2); %// changed that to respect where the markers are on your example figure 
x = 0:0.1:2 ; 
y1 = sin(2*pi*x);
y2 = exp(-0.5*2*pi*x).*sin(2*pi*x);

figure
h.axtop = subplot(2,1,1) ;
h.plottop = plot(x,y1,'LineStyle','-','Color','r', ...
                    'Marker','s', ...
                    'MarkerEdgeColor','k', ...
                    'MarkerFaceColor','none', ...
                    'MarkerSize',8) ;
set(gca,'YLim',[-1 2],'YTick',-1:1:2,'XTick',0:.5:2)
h.ylbl(1) = ylabel('\itf(t)') ;     %// label is set in "italic" mode with the '\it' tag at the beginning

h.axbot = subplot(2,1,2);
h.plotbot = plot(x,y2,'-ks', ...
                    'Marker','*', ...
                    'MarkerEdgeColor','r', ...
                    'MarkerSize',8) ;
set(gca,'YLim',[-0.2,0.6],'YTick',[-0.2,0,0.2,0.4,0.6],'XTick',0:.5:2)
h.xlbl(1) = xlabel('Time(s)') ;
h.ylbl(2) = ylabel('\itg(t)') ;     %// label is set in "italic" mode with the '\it' tag at the beginning

%// create the "text" annotations
h.txttop = text(0.5,1.5, 'Harmonic force \itf(t)=sin(\omegat)' , 'Parent',h.axtop ) ;                   %// note the 'parent' property set to the TOP axes
h.txtbot = text(0.5,0.3, 'Forced response \itg(t)=e^{\zeta\omegat} sin(\omegat)' , 'Parent',h.axbot ) ; %// note the 'parent' property set to the BOTTOM axes

%// set the common properties for all text objects in one go
set( [h.xlbl h.ylbl h.txttop h.txtbot] , 'FontName','Times New Roman' , 'FontSize',18)

: figure

, . ( ) , .

Matlab text , .

+4

All Articles