for loop store values?
Show older comments
so I am convinced there is a better way for me to approach the following code:
ftse = xlsread('ftse123.xlsx');
L = length(ftse);
s = floor(L/10);
f25 = ftse(:,3);
k=1;
h=1;
for i = 1:10
j=s*i;
h=s*(i-1);
if h== 0
h=1;
else
h=s*(i-1);
end
y{i} = f25(h:j,:);
end
x1=cell2mat(y(1));
x2=cell2mat(y(2));
x3=cell2mat(y(3));
x4=cell2mat(y(4));
x5=cell2mat(y(5));
x6=cell2mat(y(6));
x7=cell2mat(y(7));
x8=cell2mat(y(8));
x9=cell2mat(y(9));
x10=cell2mat(y(10));
I used copy and paste after struggling to save the values x1 etc, within the for loop.
Also noticed that x1 is has a length of 522 and not 523 like the rest?
The code achieves what I want/need but must be long and drawn out.
any advice would be great thanks.
2 Comments
"I used copy and paste after struggling to save the values x1 etc, within the for loop."
Copy-and-pasting code is a sign that you are doing something wrong. Using numbered variables is a sign that you are doing something wrong. The solution to both of these: use indexing.
Please upload ftse123.xlsx so that we have something to work with.
Phil Whitfield
on 1 Aug 2018
Accepted Answer
More Answers (1)
Ashraf Rayed
on 12 May 2020
0 votes
i have this code, i have to check the leaf area of some pictures in a folder and then i have save the area of those leaves by sequence in an excel sheet. Can you please help to sort out the problem?
D = 'F:\MATLAB\R2018a\bin\rayed mat lab\experimental';
S = dir(fullfile(D,'*.jpg'));
for k = 1:numel(S)
F = fullfile(D,S(k).name);
I = imread(F);
ih=rgb2hsv(I);
ih1=ih(:,:,1);
binary=ih1>0.6;
leafArea = sum(binary(:))
subplot(2, 2, 2);
imshow(binary, []);
message = sprintf('The leaf area = %d pixels.\n pixels = %.1f%%',...
leafArea, defectArea/leafArea*100);
uiwait(msgbox(message))
end
Categories
Find more on Programming 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!