How can I use this code for stabilogram diffusion analysis (SDA)?
Mostrar comentarios más antiguos
clear; clc; close;
%% SDA Analysis
% Use this file to calculate the SDA parameters for the High- and Low-CMP
% condition. Results will be stored in the 'Results' variables (either
% _HighCMP or _LowCMP).
% These files contain the following outcomes:
% Column 1 - Mediolateral critical time
% Column 2 - Mediolateral critical value
% Column 3 - Mediolateral short-term diffussion coefficient
% Column 4 - Mediolateral long-term diffussion coefficient
% Column 5 - Anterior-posterior critical time
% Column 6 - Anterior-posterior critical value
% Column 7 - Anterior-posterior short-term diffussion coefficient
% Column 8 - Anterior-posterior long-term diffussion coefficient
%% Specify data path locations (of input and output) here:
% Input
datapatho='C:\Users\megan\OneDrive\デスクトップ\914\データ\6\COP\';
% Output
datapathc='C:\Users\megan\OneDrive\デスクトップ\914\データ\6\COP\6r1cop.csv\';
%% Low-CMP condition
condition = 1;
Files=char('6r1cop.csv');
for i = 1:length(Files)
datafiles=strtrim(Files(i,:));
[param_E(:,i)]=cpdf_CMP(datapatho,datapathc,datafiles,condition);
end
Results_LowCMP = param_E';
%% High-CMP Condition
condition = 2;
Files=char('6r1cop.csv');
for i = 1:length(Files)
datafiles=strtrim(Files(i,:));
[param_I(:,i)]=cpdf_CMP(datapatho,datapathc,datafiles,condition);
end
Results_HighCMP = param_I';
%%
Respuestas (1)
Walter Roberson
el 11 de Mzo. de 2023
Files=char('6r1cop.csv');
That is a 1 x 10 character vector.
for i = 1:length(Files)
length(VARIABLE) is defined as:
take size() of variable
if any of the dimensions were 0, length is 0
otherwise length is max() of the dimensions
so for the 1 x 10 character vector, length() is 10.
datafiles=strtrim(Files(i,:));
You are trying to use up to 10 as the row number, but there is only one row.
If you want i to only be valid row numbers, use size(Files,1) or (newer MATLAB) height(Files)
% Input
datapatho='C:\Users\megan\OneDrive\デスクトップ\914\データ\6\COP\';
% Output
datapathc='C:\Users\megan\OneDrive\デスクトップ\914\データ\6\COP\6r1cop.csv\';
is 6r1cop.csv a file inside C:\Users\megan\OneDrive\デスクトップ\914\データ\6\COP\ or is it a folder in that location?
10 comentarios
康二 中西
el 11 de Mzo. de 2023
Walter Roberson
el 11 de Mzo. de 2023
Please edit your posting to format the code.
Remove the existing code. Then click on the > button in the CODE section of the edit toolbar, which will open a code region in the editor. Copy your code out of your .m file and paste it into the code region here. That will insert the formatted code into your posting.
Walter Roberson
el 11 de Mzo. de 2023
You might want to consider something like
filenums = [3:4, 7:23, 26:53];
low_names = "P" + filenums + "_E.mat";
high_names = "P" + filenums + "_I.mat";
for i = 1 : length(low_names)
datafiles = low_names(i);
param_E(:,i) = cpdf_CMP(datapatho,datapathc,datafiles,condition);
end
Results_LowCMP = param_E';
康二 中西
el 12 de Mzo. de 2023
Editada: Walter Roberson
el 12 de Mzo. de 2023
Files=char('6r1cop.csv');
sz = size(Files)
if any(sz == 0)
length_Files = 0;
else
length_Files = max(sz);
end
fprintf('according to definition, length of Files is %d\n', length_Files);
fprintf('this compares to the result of length() which is %d\n', length(Files));
You can see that length() of '6r1cop.csv' is 10.
for i = 1 : length(Files)
try
Files(i,:);
fprintf('succeeded accessing row %d of Files\n', i);
catch ME
fprintf('failed accessing row %d of Files\n', i);
break
end
end
What does this tell you?
Answer: it tells you that your code
Files=char('6r1cop.csv');
for i = 1:length(Files)
datafiles=strtrim(Files(i,:));
is wrong. You want to loop over the rows in the Files variable, but length(Files) does not tell you how many rows are in Files. length(Files) tells you 0 if any dimension of Files is empty and otherwise it tells you the largest dimension of Files. When you have more columns then you have rows then length() will be the number of columns.
So you need to rewrite the for i = 1:length(Files) loop so that you are looping over the number of rows not over length() .
康二 中西
el 13 de Mzo. de 2023
Editada: Walter Roberson
el 14 de Mzo. de 2023
Walter Roberson
el 14 de Mzo. de 2023
NO.
See the two lines I marked with "THIS WAS CHANGED"
%% SDA Analysis
% Use this file to calculate the SDA parameters for the High- and Low-CMP
% condition. Results will be stored in the 'Results' variables (either
% _HighCMP or _LowCMP).
% These files contain the following outcomes:
% Column 1 - Mediolateral critical time
% Column 2 - Mediolateral critical value
% Column 3 - Mediolateral short-term diffussion coefficient
% Column 4 - Mediolateral long-term diffussion coefficient
% Column 5 - Anterior-posterior critical time
% Column 6 - Anterior-posterior critical value
% Column 7 - Anterior-posterior short-term diffussion coefficient
% Column 8 - Anterior-posterior long-term diffussion coefficient
%% Specify data path locations (of input and output) here:
% Input
datapatho='C:\Users\elmar\OneDrive\Desktop\Onderzoek\Brunel\Research\Projects\Brunel\CMP - IF vs EF and individual differences in older adults\SDA\Input\';
% Output
datapathc='C:\Users\elmar\OneDrive\Desktop\Onderzoek\Brunel\Research\Projects\Brunel\CMP - IF vs EF and individual differences in older adults\SDA\Output\';
%% Low-CMP condition
condition = 1;
Files=char('P3_E.mat','P4_E.mat','P7_E.mat','P8_E.mat','P9_E.mat','P10_E.mat','P11_E.mat','P12_E.mat','P13_E.mat','P14_E.mat','P15_E.mat','P16_E.mat','P17_E.mat','P18_E.mat','P19_E.mat','P20_E.mat','P21_E.mat','P22_E.mat','P23_E.mat','P26_E.mat','P27_E.mat','P28_E.mat','P29_E.mat','P30_E.mat','P31_E.mat','P32_E.mat','P33_E.mat','P34_E.mat','P35_E.mat','P36_E.mat','P37_E.mat','P38_E.mat','P39_E.mat','P40_E.mat','P41_E.mat','P42_E.mat','P43_E.mat','P44_E.mat','P45_E.mat','P46_E.mat','P47_E.mat','P48_E.mat','P49_E.mat','P50_E.mat','P51_E.mat','P52_E.mat','P53_E.mat');
for i = 1:size(Files,1) %THIS WAS CHANGED
datafiles=strtrim(Files(i,:));
[param_E(:,i)]=cpdf_CMP(datapatho,datapathc,datafiles,condition);
end
Results_LowCMP = param_E';
%% High-CMP Condition
condition = 2;
Files=char('P3_I.mat','P4_I.mat','P7_I.mat','P8_I.mat','P9_I.mat','P10_I.mat','P11_I.mat','P12_I.mat','P13_I.mat','P14_I.mat','P15_I.mat','P16_I.mat','P17_I.mat','P18_I.mat','P19_I.mat','P20_I.mat','P21_I.mat','P22_I.mat','P23_I.mat','P26_I.mat','P27_I.mat','P28_I.mat','P29_I.mat','P30_I.mat','P31_I.mat','P32_I.mat','P33_I.mat','P34_I.mat','P35_I.mat','P36_I.mat','P37_I.mat','P38_I.mat','P39_I.mat','P40_I.mat','P41_I.mat','P42_I.mat','P43_I.mat','P44_I.mat','P45_I.mat','P46_I.mat','P47_I.mat','P48_I.mat','P49_I.mat','P50_I.mat','P51_I.mat','P52_I.mat','P53_I.mat');
for i = 1:size(Files,1) %THIS WAS CHANGED
datafiles=strtrim(Files(i,:));
[param_I(:,i)]=cpdf_CMP(datapatho,datapathc,datafiles,condition);
end
Results_HighCMP = param_I';
%%
康二 中西
el 14 de Mzo. de 2023
Editada: Walter Roberson
el 14 de Mzo. de 2023
Walter Roberson
el 14 de Mzo. de 2023
Error message translates as approximately
Input must be a string, character array, or cell array of character arrays.
Walter Roberson
el 14 de Mzo. de 2023
filename = '6still2COP.csv' ;%ファイル名をコピペしてください.「.csv」部分は触らないように.
ReadingStart = 1;%データ読み込み開始行
raw = csvread(filename,ReadingStart,0);%数値のみの行列の場合は関数このままでOK
There you are reading the contents of that particular file.
Text = raw;
csvread() never returns text. Never. Text always causes csvread() to error out, unless it is in a header row you told csvread to skip, or is in a leading column that you told csvread to skip.
So you raw variable will always be numeric, and that numeric value will be copied to the variable named Text
Later you have
Files=Text;
so Files will be numeric.
You then try to strtrim() a numeric value, which fails.
These days you should almost never use csvread(): use readtable() or readmatrix() or readcell() or fileread() or readlines() for most bulk reading. (There are some places to use textscan() as well.)
Categorías
Más información sobre Data Type Identification en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!