How can i put my output numbers in for loop to an array

1 回表示 (過去 30 日間)
Fatih Nurcin
Fatih Nurcin 2014 年 6 月 17 日
回答済み: ubaid haroon 2017 年 3 月 1 日
z=('/Users/fatihnurcin/Desktop/Dandnd/dilated')
cd(z)
list = dir('*.bmp');
for i = 1:length(list)
img{i} = imread(list(i).name);
end
for i = 1:length(list)
a=img{i};
b=im2bw(a,0.20);
figure
subplot(1,3,1);
imshow(b)
c=b(120,100:250);
subplot(1,3,3);
plot(c);
for n=1:length(c);
d= padarray(c,[0 1],'replicate','post');
e(n)=d(n)-d(n+1);
left=find(e==1);
right=find(e==-1);
f=right-left;
end
f
end
This is my whole code, it takes a row from a binary photo and tries to find where its black and where its not and calculate the black area so i want to ask how can i put my outputs(outputs are numbers calculated due to black arena) in an array, i couldn't do it by adding (n) to left and right,
left(n)=find(e(n)==1);
right(n)=find(e(n)==-1);
f(n)=right(n)-left(n);
I need an urgent help , i need to deliver my project in 2 days :/
  1 件のコメント
Joseph Cheng
Joseph Cheng 2014 年 6 月 17 日
reformatted to be readable.
z=('/Users/fatihnurcin/Desktop/Dandnd/dilated')
cd(z)
list = dir('*.bmp');
for i = 1:length(list)
img{i} = imread(list(i).name);
end
for i = 1:length(list)
a=img{i};
b=im2bw(a,0.20);
figure subplot(1,3,1);
imshow(b)
c=b(120,100:250);
subplot(1,3,3);
plot(c);
for n=1:length(c);
d= padarray(c,[0 1],'replicate','post');
e(n)=d(n)-d(n+1);
left=find(e==1);
right=find(e==-1);
f=right-left;
end
f
end

サインインしてコメントする。

採用された回答

Jason Nicholson
Jason Nicholson 2014 年 6 月 17 日
This assumes the bitmaps are all the same size:
myArray = [img{:}];
  5 件のコメント
Jason Nicholson
Jason Nicholson 2014 年 6 月 18 日
Can you give me some data so I can work out the issue?
Jason Nicholson
Jason Nicholson 2014 年 6 月 18 日
Honestly, it is clear to me you don't really know what you are doing with MATLAB. After this project is done, you need to read up "getting started" documents for MATLAB. The code below is ugly but works. I believe it is what you want as well.
list = dir('*.bmp');
% preallocate cell array
img = cell(length(list),1);
f = cell(length(list), 250-100);
for i = 1:length(list)
img{i} = imread(list(i).name);
end
for i = 1:length(list)
a=img{i};
b=im2bw(a,0.20);
figure;
subplot(1,3,1);
imshow(b)
c=b(120,100:250);
subplot(1,3,3);
plot(c);
for n=1:length(c);
d= padarray(c,[0 1],'replicate','post');
e(n)=d(n)-d(n+1);
left=find(e==1);
right=find(e==-1);
f{i, n} = right-left;
end
end

サインインしてコメントする。

その他の回答 (2 件)

Shravankumar P
Shravankumar P 2014 年 6 月 18 日
I guess you may go for index mapping. I just give you Idea try this once
for m=1:4
for n=1:4
X(m,n)=x(4*(m-1)+n);
end
end
x is the input which of your interest to put into an array X

ubaid haroon
ubaid haroon 2017 年 3 月 1 日
what would you do if during the loop, those arrays are different lengths?

カテゴリ

Help Center および File ExchangeDigital Filter Design についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by