Bio formats in Matlab - Bfopen - string for filename

I'm trying to read in Zeiss Zen .czi files from a directory with bfopen,
Directory="/home/ian/Zenfiles/airy-neuron/";
Dirlist=dir(fullfile(Directory,'*.czi'));
Filecounter=2 %a loop in full code
Filenamein=Dirlist(Filecounter).name
Newimagename=fullfile(Directory+Filenamein);
Newimage=bfopen(Newimagename);
This appears to produce a correctly formatted file name eg "/home/ian/Zenfiles/airy-neuron/Tile0.czi" but it produces an error -
Error using bfGetReader (line 43)
The value of 'id' is invalid. It must satisfy the function: ischar.
Error in bfopen (line 114)
r = bfGetReader(id, stitchFiles);
Manually typing the file, it appears bfopen needs it written as '/home/ian/Zenfiles/airy-neuron/Tile0.czi' but I can't get that to manifest in the code. I'm probably missing something obvious but I'm going slowly mad. Can anyone help? I have a Tb of images to get through..

 Accepted Answer

Directory = '/home/ian/Zenfiles/airy-neuron/';
Dirlist = dir(fullfile(Directory,'*.czi'));
Filecounter = 2 %a loop in full code
Filenamein = Dirlist(Filecounter).name
Newimagename = fullfile(Directory, Filenamein);
Newimage = bfopen(Newimagename);
OR use your existing code except
Newimage = bfopen(char(Newimagename));
bfopen() does not handle string objects. Your Directory is a string object and you used "+" to concatenate to it, producing a string object result. fullfile() would not be doing anything useful there, but fullfile() has the property that it returns a string object if any input is a string object, so your Newimagename is coming out as a string object.

4 Comments

Putting the comma in on Newimagename= didn;t work for me but the second option solved it
thanks
Putting the comma in is not the only change I made in the first option: Notice I switched from double quotes to single quotes.
I'll get myself some new glasses...
You can change fonts or increase font size as well.

Sign in to comment.

More Answers (1)

As seen on the error, you have to provide a file path as a character array.
Quotation marks denote strings, you can adjust your code
Newimagename=char(fullfile(Directory+Filenamein));
Fixed
Newimagename=char(fullfile(Directory,Filenamein));

Categories

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!