Question

please help me with this MATLAB CODE and explain to me what each line does and what is used for? leave your comments as words, not as pictures.

clear all; close all; For a script file, you better start with clear all and close all However, for a fucntion, you better NO

.....................................................................................................................................................................

clear all; close all; % For a script file, you better start with clear all and close all

                       % However, for a fucntion, you better NOT to start

                       % with them

%% End of cell mode example

%% Plot function

t = 0:0.1:5;

x1 = sin(2*5*t); x2 = cos(3*7*t);

figure(1)

subplot(311),plot(t,x1,'r-o'),hold on;

subplot(311),plot(t,x2, 'k:^'),hold off;

title('Lab #4');

subplot(312),plot(t,x1,'Linewidth',10),hold on;

subplot(312),plot(t,x2,'Linewidth',3),hold off;

grid on;

subplot(313),plot(t,x1,'c-s',t,x2,'m:>');

xlabel('time [sec]'); ylabel('values');

legend('x1','x2');

%% End of Plot function

%% 3D plotting

t = 0:2*pi/100:15*pi;

x1 = sin(t); x2 = cos(t);

figure(2)

plot3(x1,x2,t,'r*','Linewidth',2); axis off;

figure(3)

plot3(x1,x2,t,'r*','Linewidth',2); axis on; grid on;

xlabel('x1'); ylabel('x2'), zlabel('t');

title('A helix example in Plot3 Help file'); legend('line');

%% End of 3D plotting

%% File I/O function, "save"

clear all; close all; clc;

x = [1 2 3; 4 5 6; 7 8 9];

y = 0:2:10; z = 1:3:15;

save('myvariables','x','y','z'); %check your directory what file is made.

%% End of File I/O function, "save"

%% File I/O function, "load"

clear all; clc; %At this point, there is no variable in your workplace

MySTR = 'ENGR320 labs';

whos

load('myvariables.mat');

whos %Check what variables are loaded in your work place!!

%% End of File I/O function, "load"


0 0
Add a comment Improve this question Transcribed image text
Answer #1

clear all; close all; % For a script file, you better start with clear all and close all

                       % However, for a fucntion, you better NOT to start

                       % with them

%% End of cell mode example

%% Plot function

%%Initializing time axis from 0 to 5 with stepping of 0.1

t = 0:0.1:5;

%%x1 and x2 are the two target variables based on value of t given to it in sine and cosine functions

x1 = sin(2*5*t); x2 = cos(3*7*t);

%initializes the first figure for the output plot

figure(1)

%%[should be subplot(3,1,1)] It will be the first plot of a 3X1 grid output,hold on retains plots in the current axes so that new plots added to the axes do not delete existing plots

subplot(311),plot(t,x1,'r-o'),hold on;

%%[should be subplot(3,1,1)] It will make a plot on the first row in a single column, hold off sets the hold state to off so that new plots added to the axes clear existing plots and reset all axes properties

subplot(311),plot(t,x2, 'k:^'),hold off;

%% Label for the plot is 'Lab4' at the top of the first plot

title('Lab #4');

%%[should be subplot(3,1,2)] It will be the second plot of a 3X1 grid output, just below the previous plot,hold on retains plots in the current axes so that new plots added to the axes do not delete existing plots

subplot(312),plot(t,x1,'Linewidth',10),hold on;

%%[should be subplot(3,1,2)] It will make a plot on the first row in a single column, hold off sets the hold state to off so that new plots added to the axes clear existing plots and reset all axes properties

subplot(312),plot(t,x2,'Linewidth',3),hold off;

%%grid on displays the major grid lines for the current axes or chart returned by the gca(get current axis) command. Major grid lines extend from each tick mark.

grid on;

subplot(313),plot(t,x1,'c-s',t,x2,'m:>');

%%puts labels of the plot, i.e., on the x axis as 'time[sec]' and y axis as 'values'

xlabel('time [sec]'); ylabel('values');

%%legend creates a legend with descriptive labels for each plotted data series i.e., x1 and x2

legend('x1','x2');

%% End of Plot function

%% 3D plotting

%% used to calculate time

t = 0:2*pi/100:15*pi;

%%x1 and x2 are the two target variables based on value of t given to it in sine and cosine functions

x1 = sin(t); x2 = cos(t);

%initializes the second figure for the output plot

figure(2)

%%plots the only plot in the figure 3, here "axis off" is used

plot3(x1,x2,t,'r*','Linewidth',2); axis off;

%%initializes the first figure for the output plot

figure(3)

%%plots the only plot in the figure 3, here "grid on" is used as describe in a previous comment and "axis on"

plot3(x1,x2,t,'r*','Linewidth',2); axis on; grid on;

%%puts labels of the plot, i.e., on the x axis as 'x1' and y axis as 'x2', z axis as 't' for the 3D plot

xlabel('x1'); ylabel('x2'), zlabel('t');

%%title for the plot3 and the legent for the plot is set as 'line' for reference

title('A helix example in Plot3 Help file'); legend('line');

%% End of 3D plotting

%% File I/O function, "save"

clear all; close all; clc;

%%x,y,z are inputs from the user, X is a 3X3 array, y is a 0 to 10 range with a stepping of 2, z is a range of 1 to 15 with a stepping of 3

x = [1 2 3; 4 5 6; 7 8 9];

y = 0:2:10; z = 1:3:15;

%%this used to store the input data in the variables

save('myvariables','x','y','z'); %check your directory what file is made.

%% End of File I/O function, "save"

%% File I/O function, "load"

clear all; clc; %At this point, there is no variable in your workplace

%%a variable in which string 'ENGR320 labs' is stored

MySTR = 'ENGR320 labs';

whos

%%used to load the matlab file 'myvariables.mat'

load('myvariables.mat');

whos %Check what variables are loaded in your work place!!

%% End of File I/O function, "load"

Add a comment
Know the answer?
Add Answer to:
please help me with this MATLAB CODE and explain to me what each line does and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MATLAB code for a double pendulum. Please explain each lines for these codes pls. -------------------------------------...

    MATLAB code for a double pendulum. Please explain each lines for these codes pls. ---------------------------------------------------------------------------- clc close all clear all %---------Parameters------------------------------------------------------ L1=1; L2=1 ; M_1=2 ; M_2=1; G=9.8; %---------initial condition----------------------------------------------- tspan=30; theta1=3; theta1_prime=0; theta2=2.5; theta2_prime=0; y0=[theta1 theta1_prime theta2 theta2_prime]; [t,y]=ode45(@pend, [0 ,tspan],[ 3 0 2 0]); %---position of mass 1 and mass 2---------------------------------------- x1=L1*sin(y(:,1)); y1=-L1*cos(y(:,1)); x2=L1*sin(y(:,1))+l2*sin(y(:,3)); y2=-L1*cos(y(:,1))-l2*cos(y(:,3)); %------visualizing the result--------------------------------------------- figure(1) plot(x1,y1,'linewidth',2) hold on plot(x2,y2,'r','linewidth',2) h=gca; get(h,'fontSize') set(h,'fontSize',14) xlabel('X','fontSize',14); ylabel('Y','fontSize',14); title('Chaotic Double Pendulum','fontsize',14) fh = figure(1); set(fh, 'color', 'white'); figure(2)...

  • Please help me with this MATLAB programming problem! Im coding iin MATLAB2018 if that makes any d...

    Please help me with this MATLAB programming problem! Im coding iin MATLAB2018 if that makes any difference! The first picture is the question i need to answer. The picture below is used as reference to answer the question. The last picture (below) is the into to the problem, and is used as reference. 1. Use Matlab to create the following single plot with three subplots. All titles, gridlines, and axis labels should be as shown. Arc System Response 15 E...

  • Hello. I need help modifying this MatLab code. This is a basic slider-crank animation. the current...

    Hello. I need help modifying this MatLab code. This is a basic slider-crank animation. the current program stops the animation and then has the crank move backward. I need the crank to instead to move in full 360 degrees circular motion. Exactly like how a slide-crank mechanism works in real life. thank you and here is the code. %%Code Begins Here%% L1=0.2; L2=0.45; W=0.5; tt=linspace(0,15); for i=1:length(tt)     x2=@(t) L2+L1*sin(W*t);     y2=0;     X2=x2(tt(i));     Y2=y2;     sol= fsolve(@(x,x2,y2) root2d(x,X2,Y2),...

  • write comments for each line of the matlab code and explain . I need explanation in...

    write comments for each line of the matlab code and explain . I need explanation in each line clear all; close all; load nb2_noise_data.mat; fs = 1000; N = 256; fl1 = 170; fh1 = 230; fl2 = 370; fh2 = 430; f = [0, fl1, fl1, fh1, fh1, fl2, fl2, fh2, fh2, fs/2] /(fs/2); G = [0, 0 ,1 , 1 , 0, 0, 1, 1, 0 , 0 ]; figure; plot(f*(fs/2),G); [b,a] = yulewalk(12,f,G); X = filtfilt(b,a,x); f...

  • Below is the MATLAB code of low-cut shelving filter which can cut the low frequency of given music signal and low-boost...

    Below is the MATLAB code of low-cut shelving filter which can cut the low frequency of given music signal and low-boost shelving filter which can boost the low frequency of given music signal. Design your low-boost shelving filter and low-cut shelving filter to have noticeablly different sound. Compare the sounds of two music signals after filtering, and explain the difference in sounds briefly. If there are any mistakes in code, correct them.   Low-cut shelving filter code: close all, clear all,...

  • Is the function being called correctly? format shorteng r = linspace(0.1,4,500); % Distance in Angstrom re...

    Is the function being called correctly? format shorteng r = linspace(0.1,4,500); % Distance in Angstrom re = 0.7414; % Equilibrium Seperation D = 38292; % Dissoc Enrgey [cm^-1] twoBeta = 1.4426; Vm = morse_potential(D, twoBeta, re, r); % Call Morse Potential Function plot(r,Vm, 'g-','Linewidth',2) xlabel('Distance [A]') ylabel('Potential Energy [cm^-1]') title('Morse Potential of Hydrogens') ylim([0,5e4]) grid 'on' hold on D2 = 38292; % Equiibrium distance re2 = 0.7413; % Width of the potential well for H2 twoBeta2 = 1.4433; r =...

  • I DESPERATELY NEED HELP WITH THIS DIFFERENTIAL EQUATIONS MATLAB ASSIGNMENT IM SUPPOSED TO BE LEARNING BUT...

    I DESPERATELY NEED HELP WITH THIS DIFFERENTIAL EQUATIONS MATLAB ASSIGNMENT IM SUPPOSED TO BE LEARNING BUT WE HAVE A SUB AND HE DIDN'T TEACH IT! ITS EULER AND IMPROVED EULER IN MATLAB! HERE IS THE LINK FOR THE IMAGE FILE THAT SHOWS THE FULL INSTRUCTIONS FOR THE CODE. https://imgur.com/a/gjmypLs Also, here is my code so far that I borrowed form an old assignment but the data is all wrong and the application of the code is slightly different so either...

  • I need help in MATLAB. I'm working on a circuits lab report and I want to...

    I need help in MATLAB. I'm working on a circuits lab report and I want to plot the derivative of an input signal. The circuit is a differentiator OpAmp. It is receiving a triangle wave as an input and should output a square wave. (I've included my existing code.) The output formula is: Vout = -(Rf)*C*(dVin/dt) Where Rf is feedback resistance: Rf = 1*10^6; and C = 1*10^-6. EXISTING CODE: %% This section is copied, and then modified from another...

  • write a matlab code that can plot 3 excel files? this plot know can run one...

    write a matlab code that can plot 3 excel files? this plot know can run one excel file of 20crackf1. clc; clear all; close all; data1=xlsread('20f1','spectrum - PXI1Slot4_ai0','A8:B10009');% Importing excel file x=data1(:,1); y=data1(:,2); plot(x,y); xlim([0 100]); xlabel('Frequency in Hz'); ylabel('Amplitude in g'); title('FFT'); hold on; data2=xlsread('20crackf1','a1','A1:B5000'); x1=data2(:,1); y1=data2(:,2); plot(x1,y1); xlim([0 100]);

  •    MATLAB SCRIPT PLEASE Matlab MATH 210 in 2020 Homework Assignment 8- Due 3/25, 11:59PM Each...

       MATLAB SCRIPT PLEASE Matlab MATH 210 in 2020 Homework Assignment 8- Due 3/25, 11:59PM Each plot should have its own figure associated with it. In all questions, give the figure a title, and label the acis. Save your matlab script as drill 10.m Do not use the fplot command. 1. Plot the function f(x) = (x + 5)2 for -5 <<<10. Include a plot title, and label both aris. 2. Use the subplot command to make two plots of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT