Matlab load() command error when loading a saved cell from a .mat file

Hello, System: Matlab version: R2013a (8.1.0.604), 64-bit on windows 7 My problem: I have created a cell variable idx1 using a rangesearch function:
idx1 = rangesearch(b_values_50,2.1897,0.001);
b_values is a vector of type double. Then I save the cell to a .mat file:
save('idx1_index.mat','idx1') or
save('idx1_index.mat','idx1','-v7.3') or
save('idx1_index.mat','idx1','-v7')
I have attached this file below. Then I try to load it:
load('idx1_index.mat','-mat') or
load('idx1_index.mat') or
load('idx1_index')
And I get this popup:
And I get all these errors (below). Please comment with any solutions. Thanks Exception occurred during event dispatching:
java.lang.ClassCastException: [D cannot be cast to [Z
at com.mathworks.mlwidgets.array.ValuePanel$ROML.matlabEvent(ValuePanel.java:224)
at com.mathworks.jmi.MatlabMCR$AWTReplyEvent.run(MatlabMCR.java:1675)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at com.mathworks.mwswing.MJDialog.show(MJDialog.java:311)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at com.mathworks.mwswing.MJOptionPane.showOptionDialog(MJOptionPane.java:531)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:436)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:426)
at com.mathworks.mlwidgets.array.ArrayDialog$1.run(ArrayDialog.java:48)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception occurred during event dispatching:
java.lang.ClassCastException: [D cannot be cast to [Z
at com.mathworks.mlwidgets.array.ValuePanel$ROML.matlabEvent(ValuePanel.java:224)
at com.mathworks.jmi.MatlabMCR$AWTReplyEvent.run(MatlabMCR.java:1675)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at com.mathworks.mwswing.MJDialog.show(MJDialog.java:311)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at com.mathworks.mwswing.MJOptionPane.showOptionDialog(MJOptionPane.java:531)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:436)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:426)
at com.mathworks.mlwidgets.array.ArrayDialog$1.run(ArrayDialog.java:48)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at com.mathworks.mwswing.MJDialog.show(MJDialog.java:311)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at com.mathworks.mwswing.MJOptionPane.showOptionDialog(MJOptionPane.java:531)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:436)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:426)
at com.mathworks.mlwidgets.array.ArrayDialog$1.run(ArrayDialog.java:48)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception occurred during event dispatching:
java.lang.ClassCastException: [D cannot be cast to [Z
at com.mathworks.mlwidgets.array.ValuePanel$ROML.matlabEvent(ValuePanel.java:224)
at com.mathworks.jmi.MatlabMCR$AWTReplyEvent.run(MatlabMCR.java:1675)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at com.mathworks.mwswing.MJDialog.show(MJDialog.java:311)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at com.mathworks.mwswing.MJOptionPane.showOptionDialog(MJOptionPane.java:531)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:436)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:426)
at com.mathworks.mlwidgets.array.ArrayDialog$1.run(ArrayDialog.java:48)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at com.mathworks.mwswing.MJDialog.show(MJDialog.java:311)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at com.mathworks.mwswing.MJOptionPane.showOptionDialog(MJOptionPane.java:531)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:436)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:426)
at com.mathworks.mlwidgets.array.ArrayDialog$1.run(ArrayDialog.java:48)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.Dialog$1.run(Unknown Source)
at java.awt.Dialog$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Dialog.show(Unknown Source)
at com.mathworks.mwswing.MJDialog.show(MJDialog.java:311)
at java.awt.Component.show(Unknown Source)
at java.awt.Component.setVisible(Unknown Source)
at java.awt.Window.setVisible(Unknown Source)
at java.awt.Dialog.setVisible(Unknown Source)
at com.mathworks.mwswing.MJOptionPane.showOptionDialog(MJOptionPane.java:531)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:436)
at com.mathworks.mwswing.MJOptionPane.showMessageDialog(MJOptionPane.java:426)
at com.mathworks.mlwidgets.array.ArrayDialog$1.run(ArrayDialog.java:48)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

2 Comments

When I test your .mat on R2013a on OS-X El Capitan, or on R2016a on OS-X El Capitan, I have no difficulty.
I will need to check my virtual machines to see if I happen to have MATLAB installed in Windows... I think I might.
I installed R2013a on Windows 10 and tested, and had no problem with this file.

Sign in to comment.

Answers (1)

This works fine for me
% See what's in the file before loading it
whos -file 'idx1_index.mat'
% Shows:
% Name Size Bytes Class Attributes
% idx1 1x1 296 cell
% OK, it's in there, so now load it in to a structure.
storedStructure = load('idx1_index.mat', 'idx1')
% Shows
% storedStructure =
% idx1: {[248 249 251 252 253 261 250 247 262 254 255 256 260 246 259 245 257 258 263 244 243 242 264]}
idx1Cell = storedStructure.idx1;
idx1DoubleArray = cell2mat(idx1Cell)

3 Comments

Thanks for the reply, Image Analyst,
I have also tried running the same command on an osx machine (Matlab R2015b), and I got this error: Error using cellstr (line 21) S must be 2-D.
Error in statslib.internal.getParamVal (line 38) inputs = cellstr(inputs);
Error in internal.stats.getParamVal (line 25) [selected,locs] = statslib.internal.getParamVal(inputs,kwds,argname,multok);
Error in createns (line 153) [~,i] = internal.stats.getParamVal(distMetric,distList,'Distance');
Error in rangesearch (line 128) O=createns(X,args{:},'nsmethod', nsmethod,'bucketSize',bSize);
Error in re_plot_d_window_50_in_md (line 205) idx1 = rangesearch(b_values_50,2.1897,0.001);
From what I could gather, this happened because for some reason 'kdtree' method option in rangesearch could not be used. When I used the 'exhaustive' option, it all worked fine. Not sure if this is somehow related to the original problem.
What is strange is that, I did not get an error loading in the idx1_index.mat file on the R2015b, but I did not get the "rangesearch" error listed above on R2013a. I would expect matlab to be more cross-compatible between different os's and versions.
I will try running the code you provided tomorrow on the windows machine.
Hello, Image Analyst, It seems like everything works fine on the windows machine (i.e. the loading is successful), but I still get the same error nonetheless. Both with your proposed routine and without it (using load('filename')). I am not sure if that has something to do with the machine I am working on or Matlab software version I am using. Thanks
rangesearch takes 2 arrays as the first two arguments. That's not what you're passing in (I don't think) when you do
idx1 = rangesearch(b_values_50, 2.1897, 0.001);
The first array is okay, b_values_50, but for the second argument you have a number 2.1897 instead of an array with the same number of rows as b_values_50. Why is that?

Sign in to comment.

Asked:

on 6 Jul 2016

Commented:

on 9 Jul 2016

Community Treasure Hunt

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

Start Hunting!