Hi guys,
I'm creating my very first GUI using GUIDE for a DAQ application. I am able to pull the data sets from the instrument, place them in different handles and plot each or all of them using different push buttons.
However, I would like to be able to place the acquired data passed to handles that was plotted into an array to eventually write it to an excel worksheet. I have the function for the "Save Data" button at the end of the program. I have tried a few options to save the array, but my program stores the entire sturcture and I get an error code when trying to load it. Error message: Warning: Unable to load .NET object. Saving (serializing) .NET objects into a MAT-file is not supported.
I am open to suggestions.
Thanks so much.

댓글 수: 5

Adam
Adam 2019년 2월 14일
편집: Adam 2019년 2월 14일
What are you actually trying to save when you get that error? Don't save the handles structure. Pull your data out of it into its own variable and save only that variable as e.g.
save( 'someFullPath\someFile.mat', 'myData' );
George Diamond
George Diamond 2019년 2월 14일
Thanks Adam. I was trying to save the data passed to the handle.
%Plot data
C = []; %Array for average power
function BasicGUI_OpeningFcn(hObject, eventdata, handles, varargin)
for i = 1:1:5
c = strsplit((string(dev.Query('FETC1:ARR:CW:POW?'))),','); %Fetch data from PM and convert to string
pause(1)
C(i) = str2num(c(2)); %Average Power - Convert String to Number and place in array
W(i) = datetime('now');
pause(0.5)
i=i+1;
end
handles.C = C;
handles.W = W;
guidata(hObject, handles);
For the plotting -
function pa_vg_pushbutton_Callback(hObject, eventdata, handles)
plot(handles.W,handles.C, '-o', 'LineWidth', 2)
% Configure Axes label
fontSize = 12;
axes(handles.axes1);
xlabel('DAQ Time', 'Fontweight','bold','FontSize', fontSize);
ylabel('Power (W)', 'FontWeight', 'bold','FontSize', fontSize);
legend('Power - Average','Location','northwest')
grid on;
guidata(hObject, handles);
For the "SAVE" buttion -
function pushbutton17_Callback(hObject, eventdata, handles)
data = get(handles.C);
save('data');
guidata(hObject, handles);
P.S. - When I try to load "data", it sends out the error and adds the entire structure to the workspace. I am only trying to get the numbers in "C" that was used to plot the graph.
Thanks.Sorry about the messy code. Took parts of it show here
Adam Danz
Adam Danz 2019년 2월 14일
What is the value of handles.C? Could you share a sample of that data so we can see it?
Walter Roberson
Walter Roberson 2019년 2월 14일
handles.C does not appear to be a graphics object so you should not get() it.
You might be accidentally doing get(0) and 0 is the graphics root object .
George Diamond
George Diamond 2019년 2월 14일
편집: George Diamond 2019년 2월 14일
Thanks Adam and Walter.
I've modified the code. I no long try to get "C" or "handles.C." I fould that I can just use "Save('C')" and it saves "C.mat" to the current folder.
Using save('C.mat'), I can save C to the current folder. I then have to load it to get it to the workspace which creates the warning message:
" Warning: While loading an object of class 'ActionData':
Cannot access method 'ActionData' in class 'matlab.ui.eventdata.ActionData'. "
However, it saves it to the workspace. Please see the attached images for more context.
Thanks again.
(1) Loaded using "Save" mentioned above
(2) load('C.mat')
(3) Open handles
(4) The data I would like to easily obtain using the save button
Thanks.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2019년 2월 14일

0 개 추천

handles.C is not a graphics object so you should not get() it. You should just use the contents directly.
You might be accidentally doing get(0) and 0 is the graphics root object . Or you might accidentally be getting some other object, just by chance.

댓글 수: 3

George Diamond
George Diamond 2019년 2월 14일
I modified the code. I no long try to get "C" or "handles.C." I fould that I can just use "Save('C')" and it saves "C.mat" to the current folder.
It still doesn't give me a simple way to save the data that I am looking to save. Decided to take a chance trying save('handles.C'), but it spits out a corrupted file.
C = handles.C;
save('C.mat', 'C');
George Diamond
George Diamond 2019년 2월 15일
Walter, it worked! Thanks so much. Much appreciated.
Adam, thanks too for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

질문:

2019년 2월 14일

댓글:

2019년 2월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by