My MATLAB keeps reading old .mat files as uint32 even though it ain't, why is it and how can I fix this?

19 views (last 30 days)
I thought of upgrading/updating my MATLAB, might that fix the issue?
Why is it happening in the first place?
As in:
load(data_set_path);
then if it had saved a struct there is doesn't return it but reads it as uint32 and throws error:
Warning: Variable 'data4cv' originally saved as a cross_validation_data
cannot be instantiated as an object and will be read in as a uint32.
> In pca_train (line 5)
  2 Comments
James Tursa
James Tursa on 21 Mar 2016
Looks like it was saved as an OOP object of type cross_validation_data, not a struct. Do you have the code for cross_validation_data?
Brando Miranda
Brando Miranda on 21 Mar 2016
Yes, I do:
https://github.com/brando90/research/blob/master/HBF_mat_lib/common/cross_validation/standard_train_cv_test_validation/cross_validation_data.m
or I can just copy it:
classdef cross_validation_data < handle
%
properties
X
y
per_train
per_cv
X_train
X_cv
X_test
y_train
y_cv
y_test
end
methods
function obj = cross_validation_data(X,y,per_train,per_cv)
obj.X = X;
obj.y = y;
obj.per_train = per_train;
obj.per_cv = per_cv;
%%split_data_for_hold_out_cross_validation
[~, N] = size(obj.X);
N_train = floor(N * obj.per_train);
N_cv = floor(N * obj.per_cv);
obj.X_train = obj.X(:,1:N_train);
obj.X_cv = obj.X(:, N_train+1:N_train+N_cv );
obj.X_test = obj.X(:, N_train+N_cv+1:N);
obj.y_train = obj.y(:,1:N_train);
obj.y_cv = obj.y(:, N_train+1:N_train+N_cv );
obj.y_test = obj.y(:, N_train+N_cv+1:N);
end
function [ X_train,X_cv,X_test, y_train,y_cv,y_test ] = get_data_for_hold_out_cross_validation(obj)
X_train = obj.X_train;
X_cv = obj.X_cv;
X_test = obj.X_test;
y_train = obj.y_train;
y_cv = obj.y_cv;
y_test = obj.y_test;
end
function [] = change_data_sets(obj, X_train,X_cv,X_test, y_train,y_cv,y_test)
obj.X_train = X_train;
obj.X_cv = X_cv;
obj.X_test = X_test;
obj.y_train = y_train;
obj.y_cv = y_cv;
obj.y_test = y_test;
end
% Make a copy of a handle object.
function new = copy(this)
% Instantiate new object of the same class.
new = feval(class(this));
% Copy all non-hidden properties.
p = properties(this);
for i = 1:length(p)
new.(p{i}) = this.(p{i});
end
end
function [] = normalize_data(obj)
obj.X = normc(obj.X);
obj.y = normc(obj.y);
obj.X_train = normc(obj.X_train);
obj.X_cv = normc(obj.X_cv);
obj.X_test = normc(obj.X_test);
obj.y_train = normc(obj.y_train);
obj.y_cv = normc(obj.y_cv);
obj.y_test = normc(obj.y_test);
end
end
methods (Static)
function [X_new, y_new] = shuffle_data(X,y)
[~, N] = size(X);
permute_ordering = randperm(N);
X_new = X(:, permute_ordering);
y_new = y(:,permute_ordering);
end
end
end

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 21 Mar 2016
You saved one or more objects in the MAT-file, but the definition for the object's class is not available to MATLAB when it loads the data so it doesn't know how to convert the raw data from the MAT-file into an instance of the object.
Try to remember if you were using any third-party toolboxes when you created that MAT-file. If so, check if they are still accessible to MATLAB. I'm betting that you were using such a toolbox but it is no longer available to MATLAB when you try to LOAD the file.
  2 Comments
Brando Miranda
Brando Miranda on 21 Mar 2016
I was using my own code. In fact this is the defintion of the object:
https://github.com/brando90/research/blob/master/HBF_mat_lib/common/cross_validation/standard_train_cv_test_validation/cross_validation_data.m
classdef cross_validation_data < handle
%
properties
X
y
per_train
per_cv
X_train
X_cv
X_test
y_train
y_cv
y_test
end
methods
function obj = cross_validation_data(X,y,per_train,per_cv)
obj.X = X;
obj.y = y;
obj.per_train = per_train;
obj.per_cv = per_cv;
%%split_data_for_hold_out_cross_validation
[~, N] = size(obj.X);
N_train = floor(N * obj.per_train);
N_cv = floor(N * obj.per_cv);
obj.X_train = obj.X(:,1:N_train);
obj.X_cv = obj.X(:, N_train+1:N_train+N_cv );
obj.X_test = obj.X(:, N_train+N_cv+1:N);
obj.y_train = obj.y(:,1:N_train);
obj.y_cv = obj.y(:, N_train+1:N_train+N_cv );
obj.y_test = obj.y(:, N_train+N_cv+1:N);
end
function [ X_train,X_cv,X_test, y_train,y_cv,y_test ] = get_data_for_hold_out_cross_validation(obj)
X_train = obj.X_train;
X_cv = obj.X_cv;
X_test = obj.X_test;
y_train = obj.y_train;
y_cv = obj.y_cv;
y_test = obj.y_test;
end
function [] = change_data_sets(obj, X_train,X_cv,X_test, y_train,y_cv,y_test)
obj.X_train = X_train;
obj.X_cv = X_cv;
obj.X_test = X_test;
obj.y_train = y_train;
obj.y_cv = y_cv;
obj.y_test = y_test;
end
% Make a copy of a handle object.
function new = copy(this)
% Instantiate new object of the same class.
new = feval(class(this));
% Copy all non-hidden properties.
p = properties(this);
for i = 1:length(p)
new.(p{i}) = this.(p{i});
end
end
function [] = normalize_data(obj)
obj.X = normc(obj.X);
obj.y = normc(obj.y);
obj.X_train = normc(obj.X_train);
obj.X_cv = normc(obj.X_cv);
obj.X_test = normc(obj.X_test);
obj.y_train = normc(obj.y_train);
obj.y_cv = normc(obj.y_cv);
obj.y_test = normc(obj.y_test);
end
end
methods (Static)
function [X_new, y_new] = shuffle_data(X,y)
[~, N] = size(X);
permute_ordering = randperm(N);
X_new = X(:, permute_ordering);
y_new = y(:,permute_ordering);
end
end
end

Sign in to comment.

More Answers (1)

Paul Kane
Paul Kane on 23 May 2019
If you wrote the app, open it in AppDesigner and run it. Back at the Matlab command window, you can now load your mat file and voila, Matlab now understands your structure.

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!