MATLAB: Plotting different functions at the end of eachother logical indexingplotting I have 2 functions one for 0<x<10 and one for 10<x<30. How do i plot the second one at the point where the first one ends? Best Answer fz10 = @(x)x+3;%two functionsf1030 = @(x)(x+3)*2;t = 0:20;plot(t(t<10),fz10(t(t<10)),'r*',t(t>10&t<30),f1030(t(t>10&t<30)),'b*') %logical indexing! Related SolutionsMATLAB: PLotting noisy signal matlab What do you mean suppose t was a vector? t = 0:pi/100:40; x = cos(pi/10*t)+0.5*randn(size(t)); plot(t,x)t is a vector in the above. So is x and you are plotting the vector x as a function of the vector t. MATLAB: I am getting an error as “Operands to the || and && operators must be convertible to logical scalar values. Error in xd (line 8) if (t>=t1)&&(t You cannot compare a vector t (which is 1x51 double) with a single value for an if statement, with the logical operators. Even if you could, the plot at the end won't give anything. I believe you want to do this. t1 = 0;t2 = 10;t3 = 20;t4 = 30;t = 0:50;r = zeros(length(t),1);for i = 1:length(t) if (t(i)>=t1)&&(t(i)<t2) r(i) = 0.6; elseif (t(i)>=t2)&&(t(i)<t3) r(i) = 0.3; elseif (t(i)>=t3)&&(t(i)<t4) r(i) = 0.3; else r(i) = 0.6; end endplot(t,r)axis([0 60 0.2 0.7]) Related QuestionHow to plot a selective range of x-axis valuesHide legend for certain curves in a Matlab plotHow to plot a piecewise functionHow to add an initial point to 5 curves in a plotPLotting matlab noisy signalUsing for loop for plotting from a timetableHow to Nonlinear equations?(two variables)
Best Answer