Structure inside a while loop && pixel distance

조회 수: 6 (최근 30일)
tabw
tabw 2014년 8월 12일
편집: Ben11 2014년 8월 12일
I want to create a structure that stores my array inside a loop
for Example Every time it will generate a data stored in result array. let's say, I have N result. I want to stored into a 1XN structure. How to do that inside a loop?
I have tried for i=1:10
second Qusetion, For example, I have a M x N array. a pixel (m,n) And I used j=(n-1)*M+m convert pixel into the order in Array(:) Is there a way to know the distance between two pixels?
like (3,2) and (3,3) just have 1 unit distance
s=struct('num2str(i)',{result})
But it won't work
Thanks

채택된 답변

Ben11
Ben11 2014년 8월 12일
편집: Ben11 2014년 8월 12일
Something like this?
N = 10;
YourStructure(N).result = zeros(15); % Initialize the structure
for k = 1:N
YourStructure(k).result = rand(15); % store your array in the structure;
end
EDIT:
To use a while loop (I based my previous answer on your for-loop sorry):
N = 10;
YourStructure(N).result = zeros(15);
k = 1;
while k<=N
YourStructure(k).result = rand(15);
k = k+1;
end
======= For your 2nd question, the distance is calculated like so:
Distance =sqrt((y2-y1)^2+(x2-x1)^2)
with the coordinates of the pixels being [x1 y1] and [x2 y2].

추가 답변 (1개)

Joakim Magnusson
Joakim Magnusson 2014년 8월 12일
편집: Joakim Magnusson 2014년 8월 12일
You are trying to create field names named 1,2,3 ... but that is not possible because the field name have to start with a letter.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by