Adding values to a variable in a loop?

2 views (last 30 days)
Jessica
Jessica on 17 Jul 2014
I'm having a problem putting data into a variable using a loop. I've never really worked with cell array's and they seem to be giving me problmes I'm working with z-stack confocal images and am looking to analyze the intensity within the cells. Right now I am just trying to put the data in appropriate matrices so that I can manipulate it later on.
Here is a run-down of the variable types.
ans gives 1x4 cell where the pixel and image data is in the first cell (which is the only thing I'm concerned with).
image_data gives a 135x2 cell as seen below
2048x2048 uint16 'C:\Users\Jessica\Desktop\GFP25_010.nd2; plane 1/135; C=1/3; T=1/45'
2048x2048 uint16 'C:\Users\Jessica\Desktop\GFP25_010.nd2; plane 2/135; C=2/3; T=1/45'
2048x2048 uint16 'C:\Users\Jessica\Desktop\GFP25_010.nd2; plane 3/135; C=3/3; T=1/45'
2048x2048 uint16 'C:\Users\Jessica\Desktop\GFP25_010.nd2; plane 4/135; C=1/3; T=2/45'
2048x2048 uint16 'C:\Users\Jessica\Desktop\GFP25_010.nd2; plane 5/135; C=2/3; T=2/45'
2048x2048 uint16 'C:\Users\Jessica\Desktop\GFP25_010.nd2; plane 6/135; C=3/3; T=2/45'
pixel_data is a 135x1 cell and is the first column of image_data
Below is my code. My problems is in the last little bit. I keep getting an error.
*Error message: The following error occurred converting from cell to double: Error using double. Conversion to double from cell is not possible.
Error in Image_Analysis (line 45) channel1(i,1)=pixel_data(i,1)*
%Data Analysis of Amount of Antibody Internalization in Cells
clc;
clear;
%Open Image
bfopen()
%Extract Image Data
image_data=ans{1,1};
%Create an Array focused on the pixel_data
pixel_data=image_data(:,1);
%Ask User How Many Laser Channels were used to Acquire the Image
total_laser_channels=input('How many laser channels were used to acquire this image?\n');
%Preallocate space and variables for each channel
if total_laser_channels==1
channel1=[];
elseif total_laser_channels==2
channel1=[];
channel2=[];
elseif total_laser_channels==3
channel1=[];
channel2=[];
channel3=[];
elseif total_laser_channels==4
channel1=[];
channel2=[];
channel3=[];
channel4=[];
else total_laser_channels==5
channel1=[];
channel2=[];
channel3=[];
channel4=[];
channel5=[];
end
%Loop: Each laser channel has corresponding images
i=1;
while i<length(pixel_data)+1
channel1(i,1)=pixel_data(i,1)
channel2(i-1,1)=pixel_data(i+1,1)
channel3(i-3,1)=pixel_data(i+2,1)
i=i+3;
end
To clarify what I'm trying to do with the loop. I want to know how many lasers were used. You'll notice in that in image_data C=1/3, 2/3, 3/3. These correspond to different laser channels. Thus I want to put the pixel_data of the corresponding laser channels into channel1 channel2 and channel3
Any help would be wonderful. Also any suggestions on my code would be great as well.

Answers (1)

Matz Johansson Bergström
Matz Johansson Bergström on 17 Jul 2014
It seems as though pixel_data(i,1) is still a cell. Have you tried pixel_data{i,1}?
If I try
pixel_data={1,4,7,8}
>class(pixel_data(1))
cell
>class(pixel_data{1})
double
  2 Comments
Jessica
Jessica on 17 Jul 2014
That probably would have worked. Thank you.
>> class(pixel_data(1))
ans =
cell
>> class(pixel_data{1})
ans =
uint16
However, I came up with a new little bit of code.
channel1=[channel1;pixel_data(i,1)];
channel2=[channel2;pixel_data(i+1,1)];
channel3=[channel3;pixel_data(i+2,1)];
i=i+3;
This worked for what I was trying to do

Sign in to comment.

Categories

Find more on Images 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!