Getting Data out of a Char/String
3 views (last 30 days)
Show older comments
So I can read in this huge thing from the images I'm using (nd2 files). I define pixel_data as this nX2 matrix.
The first column gives me a huge matrix that has all the pixel info in it for individual picture slices. Second column is just a char
pixel_data =
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 1/88;...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 2/88;...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 3/88;...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 4/88;...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 5/88;...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 6/88;...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 7/88;...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 8/88;...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 9/88;...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 10/88...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 11/88...'
[2048x2048 uint16] 'C:\Users\Jessica\Desktop\WT004.nd2; plane 12/88...'
...
...
...
I can define file_info as this nx1 matrix
file_info =
'C:\Users\Jessica\Desktop\WT004.nd2; plane 1/88; Z=1/44; C=1/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 2/88; Z=1/44; C=2/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 3/88; Z=2/44; C=1/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 4/88; Z=2/44; C=2/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 5/88; Z=3/44; C=1/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 6/88; Z=3/44; C=2/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 7/88; Z=4/44; C=1/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 8/88; Z=4/44; C=2/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 9/88; Z=5/44; C=1/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 10/88; Z=5/44; C=2/2'
'C:\Users\Jessica\Desktop\WT004.nd2; plane 11/88; Z=6/44; C=1/2'
...
...
...
It's stacked images of a cell. So basically I have all these slices that go from the bottom of the cell to the top of the cell showing me the distribution of different proteins that have been labeled with different dyes.
So my problem. The information in file_info is a char. I don't care about the location. Plane doesn't really matter to me. For the example I gave you above, I imaged with 2 different lasers for 2 different dyes that were used. Overall, 44 different slices were take, but at each level 2 images were taken based on the number of lasers used. As a result I have 88 planes/images. Move to the Z column, it is basically what I was just talking about, its called a Zstack image so there are 2 pictures at each Z level(slice)
*The data I want is in C. Lets call C the color for each laser. I want to know the total number of lasers used. And I want to know which laser it is 1 or 2. That way I can create matrixes to extract the pixel data of each image and organize them based on which laser. *
Note for this image there were 2 lasers. It can go up to 5 laser per image. I have some with 3 and 4.
I've looked at functions like textscan, fscanf but I'm really lost help would be appreciated greatly
0 Comments
Accepted Answer
Image Analyst
on 20 Jun 2014
How about
% Get something like 'C:\Users\Jessica\Desktop\WT004.nd2; plane 11/88; Z=6/44; C=1/2'
string = file_info{numberYouAreInterestedIn};
% Extract second to last character and convert to a number.
laserNumber = str2double(string(end-2));
You can also look at string(end) to get the last character, which I presume is the total number of laser colors used in that experiment.
totalNumberOfLasers = str2double(string(end));
More Answers (1)
Ben11
on 20 Jun 2014
Edited: Ben11
on 20 Jun 2014
You might want to use regular expressions and the "match" option. Here is a simple example:
If you write this:
file_info_C = regexp(file_info,'(C(\=\d*\/\d*))','match')
the result will be 'C=1/2'
So you basically ask regexp to match a sequence in file_info in which the letter C is followed by an equal sign, then a digit, then a / symbol and then another digit. You can play around to see what does what, but d* means any digit and \= means 'look for an equal sign'.
You could implement this in a loop to get the information about every image. If you only want the specific laser used for an image, you could cut the above code to this:
InfoLaser = regexp(file_info_C,'(?<=\=)\d*','match')
% InfoLaser{1} would give '1', so str2num(InfoLaser{1}) would give you the specific laser used for the image.
Hope that helps!
0 Comments
See Also
Categories
Find more on Convert Image Type 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!