How to create a 3-D array using information from FOR loop?

Hi there, I am currently having a problem with trying to get data out from a FOR loop and place into a 3-D array.
I have tried using Array3D= cat(3,A) within and outwith the FOR loop but cant seem to get the array to work.
Thanks

댓글 수: 4

You should show us your for loop.
Robert Roy
Robert Roy 2015년 5월 22일
편집: Matt J 2015년 5월 22일
Okay, what I am looking for is the different Img values in the 3-D array, after extracting form a specific file.
Images=20;
t=19;
AvgImg = uint16(zeros(1024,1280));
for
i=t:Images
B=readimx(fullfile(filename,['B000',int2str(i),'.im7']));
C=B.Frames{1}.Components{1};
V = C.Planes;
Img = V{1,1};
AvgImg = AvgImg + Img;
end
Which variable represents the slices that you are trying to concatenate?
Img, it think

댓글을 달려면 로그인하십시오.

 채택된 답변

Guillaume
Guillaume 2015년 5월 22일
편집: Guillaume 2015년 5월 22일
1. Predeclare the array, 2. Just assign to it using indexing instead of using concatenation that is going to be slow.
Array3D = zeros(1024, 1280, Images); %3D array of 2D images
for i = t:Images
%read frame, I've not dealt with Davis images for a while but wasn't it
%Img = B.Data ?
Array3D(:, :, i) = Img;
end

댓글 수: 3

Thanks, that gave me the right structure but none of the values out. Davis have updated there stuff so the way I have extracted is the one they suggested. I am just wonder if possible would it be easier if if it was just one row, rather than all the rows?
I've just downloaded the latest documentation of readimx, and indeed LaVision have completely changed the way it works.
The code you're using to read the images is fine. Note that I've reproduced your original indexing ( t:Images) which only reads images 19 and 20. Thus Array3D is only going to have values other than 0 for Array3D(:, :, 19) and Array3D(:, :, 20).
Doesn't this work?
nimages = 20;
Array3D = zeros(1024, 1280, nimages);
for imgidx = 1:nimages
buffer = readimx(fullfile(filename, sprintf('B%05d.im7', imgidx)));
Array3D(:, :, imgidx) = buffer.Frames{1}.Components{1}.Planes{1};
end
Also note that filename is a misleading variable name for a path. I would have called it path.
Also note the use of sprintf to construct the filename, which will create the right buffer name regardless of the number of digits in the image index.
Thanks very much, yeah I go the answer I need to work, I am just wondering if I am able to take a section from each Img in the loop and plot the pixel intensity radially on a graph with all the Img from the loop.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2015년 5월 22일

댓글:

2015년 5월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by