How to create a loop in which a number increments and
Show older comments
Here's what I want to do: I have certain data plotted, let's say a cos function. I want to give matlab a certain value, example: 5 and from the whole function I want it to divide it in 5 equal sections. And then I want to get the media of each of those 5 equally spaced sections, or the variance or whatever. I know how to get all of the data, and I know how to calculate it separately.
I was doing it like this (manually): y=x(1:50)
prom=mean(y)
But i want to assign variables so when I want the spaces to go 5 or 10 or 100, i just need to change the variable.
I don't know if I am making myself clear
Accepted Answer
More Answers (1)
KSSV
on 22 Feb 2018
N = 100 ; % should be multiple of the number of parts you want
th = linspace(0,2*pi) ;
y = cos(th) ;
plot(th,y)
% divide the section into 5 equal parts
th1 = reshape(th,5,[]) ;
y1 = reshape(y,5,[]) ;
Categories
Find more on Loops and Conditional Statements 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!