need help with regionprops function problem and how can I export command window data to an excel spreadsheet?

In the attached file there's the part of code in which i'm having problems. On the region props callback, when marking the boundaries with green line, it shows the boundaries in another axes(axes7), when it should be showing it in axes8. I've been trying to solve this problem for 2 days now and I cant seem to find a way to solve it.
also I want to know how can I save data from the command window to an excel spreadsheet when clicking on a pushbutton.

 Accepted Answer

regionprops() does not have a callback.
To switch focus to axes 8, do this
axes(handles.axes8); % If using GUIDE, use handles, otherwise don't.
hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;
You do not save anything from the command window when you're clicking on a pushbutton. The saving is done in the pushbutton callback function - you don't do it manually from the command line. To save to Excel call xlswrite() from the pushbutton callback. Or for more control and faster speed if doing multiple writes, use ActiveX like in my attached demo.

5 Comments

Burku mistakenly put this down as an "Answer" so I am moving it here:
Sir Image Analyst, I wrote that line code you told me and now it detects the boundaries in the axes 8, but it dissapears right after, when it should stay permanently visible. I put the same line code inside the for cycle, but it doesn't at the same.
As for the pushbutton callback to save data to excel spreadsheet I looked up your demo and I found it very interesting. But it's too complicated for me to create a callback function like that since I'm not an expert in matlab and just started using it few weeks ago. I wanted to know if you could help me creating a simple xlswrite() callback?
Burku: You either forgot to call "hold on" or you're plotting something after you call "hold off" and it's blowing away all the plotting you did. That's all I can guess at, since my Crystal Ball Toolbox is in the shop for repair, and therefore I can only guess at how you modified or used my code and what your code looks like.
Right click on your pushbutton and say view callback. Then put a call to xlswrite() in the callback function. I'm sure the help has examples for xlswrite().
Sir Image Analyst, I attached a file with the necessary part of my code that I think that might show where the problem resides. I used your code in the "region_prop_Callback" as you can see in the attached file. I defined the "binary image" (that you are talking) in another function (dilation) and then I called it as handles.binaryImage to perform the regionprop (see file). I looked up the help about xlswrite() and I tried to export the data displayed at the command window by defining an array to keep the data I want to export to excel (containing the data of area, perimeter,..), but its not working. I defined
I can't see anything because you forgot to attach them. Please attach the m-file and the fig file. Use the paperclip and don't forget to click the "Attach file" button like you probably did last time.
Here it is. I managed to fix (more or less) the issue about the detecting of the boundaries with the line code you told me about and by doing some modifications on other code. Sir Analyst I also tried to index the boundaries with numbers in the image according to the region props boundary detection so when the data is showed in the command window the images refering to the regions would be visible also in the image but I find find out how to do that. Also the code for exporting the data to excel doesn't work and I need to deliver all the code tomorrow to my advisor. Can you help me finding the reason why its not exporting the data please?

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Asked:

on 31 May 2014

Commented:

on 1 Jun 2014

Community Treasure Hunt

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

Start Hunting!