Specify columns inside a for loop
Show older comments
Hi
I would like to know if the code I attached will do the following: I want the value in the for loop to multiply by the price. But more specifically, I want this value to multiply by 10 if it is in the columns 1-8 and for the rest of the columns multiply by 15.
Thanks
for j=1:365
for i=1:25
if data(1,i)>=1 && data(1,i)<=8
price=10;
else
price=15;
end
Accepted Answer
More Answers (1)
Chirag Gupta
on 13 Jul 2011
You might not need to use a for loop
% rand data
data = rand(365,25);
% colums 1-8
data(:,1:8) = data(:,1:8)*10;
% colums 9 -25
data(:,9:25) = data(:,9:25)*15;
1 Comment
Nathan Greco
on 13 Jul 2011
True, but that's not what he asked.
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!