Clear Filters
Clear Filters

How to save 2 column vectors of multiple arrays existing in workspace to a .txt file or in excel file ?

3 views (last 30 days)
i got my all labeled arrays in workspace . now i want to store those arrays separately in some .txt file or in excel file .. like label 1's 2's ....max coordinates save in one file ..or it will save in multiple files having no idea about that . Help me

Accepted Answer

Image Analyst
Image Analyst on 22 Jul 2012
Edited: Image Analyst on 23 Jul 2012
I don't think you want to save them in a text file or an Excel workbook, based on reading your other posting. I think they should be images also. Use something like this (untested)
[labeledImage numberOfBlobs] = bwlabel(binaryImage, 8); % Label each blob so we can make measurements of it
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'PixelList');
for r = 1 : numberOfBlobs
% Extract blobs one at a time.
% Note how we use ismember() to do this.
oneRegion = ismember(labeledImage, r);
% Save it to disk.
baseFilename = sprintf('Region number %d.png', r);
fullFileName = fullfile(folder, baseFilename);
imwrite(oneRegion , fullFileName);
thesePixels = blobMeasurements(r).PixelList;
% Now use fopen(), fprintf(), and fclose() to write thesePixels to a disk file.
end
  2 Comments
sameen
sameen on 23 Jul 2012
sir the above code is giving me this error
??? Error using ==> regionprops Too many output arguments.
and please tell me how to store all those coordinate values in some text or excel file (which is most suitable and easily integrated with c sharp???)
Image Analyst
Image Analyst on 23 Jul 2012
Edited: Image Analyst on 23 Jul 2012
Sorry - I edited it to fix the mistake. I assume you know how (or can easily figure out how) to use fprintf() to write the coordinates to a file. Comment out the filename and imwrite line if you don't want an image file. Don't use Excel since that will take a long time - much longer than fprintf().

Sign in to comment.

More Answers (0)

Categories

Find more on Data Import from MATLAB 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!