I want to run two different increments to get two graphs simultaneously using subplot
Show older comments
%Matlab say i have mtix size issue at: x2=x2+sin(k2*t)/k2;
%running the two seperatly has no issues just combing to have graphs change side by side is a problem.
%any help spotting my errors?
clc;
clear all;
close all;
t=0:0.01:10;%time period 0.1 increments
x=zeros(size(t));%array of zeros of ssize t
x2=zeros(size(t));
for k=1:1:100, k2=1:2:100;%full sine values, odd sine values
x=x+sin(k*t)/k;%harmonics
x2=x2+sin(k2*t)/k2; %matrix mutiplication is wrong?
subplot(1,2,1), plot(x(:), 'r ')
subplot(1,2,2), plot(x2(:), 'b ')
end
1 Comment
Use the index of loops in time vector
%if true
% code
% end
x(k) = x(k)+sin(k*t(k))/k;
x2(k2)=x2(k2)+sin(k2*t(k2))/k2;
But it will plot till 0.99 sec of time of 100 sec. To plot whole of time use length(t) in for loops.
i%f true
% code
% end
for k = 1:length(t)
for k2 = 1:2:length(t)
Use a hold on between plots
Accepted Answer
More Answers (1)
John Chris Campbell
on 14 Oct 2020
0 votes
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!