Dot indexing is not supported for variables of this type. - trying to create a function to upload files matrices

조회 수: 1 (최근 30일)
I am trying to write a function that allows me to upload a chosen mat file and to take specific matrices from these files, so that these matrices can be used in another code.
I have written the following, to plot the data before writing is as a function, knowing that all signal matrices are named after the file as file.pulse0 and the time matrices are named as file.t:
name ='Woven_6';
load([name '.mat']); %I am wanting to load the 'Woven_6.mat' file
signal = name.pulse0(:,:); %I am wanting to load the 'Woven_6.pulse0' matrix
time = name.t(:,:); %I am wanting to load the 'Woven_6.t' matrix
plot(time, signal)
I intent to used this in another bit of code so that I can upload this time and signal values to calculate other variables, but I keep on getting this error:
"Dot indexing is not supported for variables of this type." - and it is stated that this error occurs on the lines 3 and 4 of the code.
As a function this would be written as:
function(signal, time, signal_reference, time_reference) = read_transmission[name]
name ='Woven_6_stepscan';
load([name '.mat']);
signal = name.pulse0(:,:);
time = name.t(:,:);
end
How can I fix the first bit of code so I can rewrite the function so that the latter works?
PS: I have seen the following link but I don't understand the answers to this question.

채택된 답변

Stephen23
Stephen23 2022년 5월 5일
편집: Stephen23 2022년 5월 6일
I am guessing that you have very badly-designed data, where the variable in the MAT file uses the same name as the file itself.
Assuming that there is exactly one variable in the MAT file, then you can obtain it like this:
F ='Woven_6.mat';
S = load(F); % Always LOAD into an output variable!
C = struct2cell(S);
assert(isscalar(C),'too many variables!')
signal = C{1}.pulse0;
time = C{1}.t;
plot(time, signal)
Better data design would not include meta-data in the variable name.
  댓글 수: 2
Goncalo Costa
Goncalo Costa 2022년 5월 6일
편집: Goncalo Costa 2022년 5월 6일
Thank you so much for your help, this worked perfectly. So, what made it not work was the fact that they were both named the same? Or just the way that the data file is?
Stephen23
Stephen23 2022년 5월 6일
"So, what made it not work was the fact that they were both named the same?"
Correct: naming the variable dynamically makes it harder or more fragile to process.
"Or just the way that the data file is?"
The data file does not have to be like that: someone designed that data to be like that.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 5월 5일
편집: Walter Roberson 2022년 5월 5일
function [signal, time, signal_reference, time_reference] = read_transmission(name)
data = load([name '.mat']);
signal = data.pulse0;
time = data.t;
signal_reference = SOMETHING;
time_reference = SOMETHING;
end
  댓글 수: 1
Goncalo Costa
Goncalo Costa 2022년 5월 5일
My data file would therefore be something like: Woven_6.mat ..... but this cannot be used for my signal as my signal is merely Woven_6.pulse0 and not Woven_6.mat.pulse0 .
Because of this I get the message: Reference to non-existent field 'pulse0'.
This is why last time I separated the data from the name. Knowing this, do you know how I could make this function open my files the way I described above?
Thank you so much for your help so far.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by