Append matrix with subsequent images
이전 댓글 표시
Hello,
I am having trouble solving a problem where I am trying to create a matrix that is later written to excel. The way the program works is that I upload an image into a GUI, and then alter the image so it is possible to count individual objects. I then have a button that saves the information to a matrix (the file name and the number of objects in the image). However, I am having trouble figuring out how to append the matrix. The way the code is set up, I am only able to create one array that only contains the latest file name and object number. I would like to be able to append the matrix with the information from subsequent images. Please let me know if you have any ideas! I imagine I would have to change the way new images are being stored (instead of just making the name and number equal to "x"). Would I have to write a loop in order to make this happen?
Additionally, I have tried using "xlsappend", but I keep receving this errror:
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUI('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Array indices must be positive integers or logical values.
Error in GUI>pushbutton4_Callback (line 120)
Image_New_Name = name(Last_Characters:(Last_Characters+2));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUI (line 17)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)GUI('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
This is how I search for and upload the image:
function pushbutton1_Callback(hObject, eventdata, handles)
%Define image as a useable variable by reading it from a folder
[Filename, Pathname]=uigetfile('*.jpg', 'File Selector');
global name
name=strcat(Pathname, Filename);
global Current_Image
Current_Image=imread(name);
set(handles.Browse, 'string', name);
axes(handles.axes1);
imshow(Current_Image);
This is how the program counts the images (bw2 is the file name, I figured I would spare everyone from the 20 lines of code that alters the image)
cc = bwconncomp(bw2,4);
global number
number = cc.NumObjects;
set(handles.text4,'string',number);
This is the button that saves the image information
function pushbutton4_Callback(hObject, eventdata, handles)
global number
global name
Image_Name_Length = length(name);
Last_Characters = (Image_Name_Length - 6);
Image_New_Name = name(Last_Characters:(Last_Characters+2));
New_Name_String = {Image_New_Name};
x = [New_Name_String, number]
header={'Image', 'Cells'};
xlswrite('Image Counter', header, 'Sheet1');
xlswrite('Image Counter', x, 'Sheet1');
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!