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?
채택된 답변
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
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
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!