Dot indexing is not supported for variables of this type
조회 수: 4(최근 30일)
표시 이전 댓글
The script does create the variable vel. It is a 1x1 struct with data and headers.
Any ideas why the error is still reported? Thanks in advance (script in attachment)
댓글 수: 8
Lissa
2021년 5월 1일
startpath = ('/MATLAB Drive/BIOMECHLISSA')
timecolumns = importdata('/MATLAB Drive/BIOMECHLISSA/Timing-IMU-viconNEW.xlsx');
for k = 1:2
starttimeIMU = timecolumns(k,5) % SUP HR IMU
starttimeOS = timecolumns(k,6) % SUP HR OPENSIM
%%%%%%%%%%%%%%%%%%%% PART ONE %%%%%%%%%%%%%%%%%%%%%%%
%%% IMU %%%
addpath ('/MATLAB Drive/BIOMECHLISSA/RAW IMU') % IMU data inladen, van Jente gekregen = dit exporteert alle IMU data
name = sprintf('MATLAB Drive/BIOMECHLISSA/RAW IMU/Sup_HR_Trial0%d_data.mat',k)
load(name);
Hinge = sprintf('MATLAB Drive/BIOMECHLISSA/RAW IMU/Sup_HR_Trial0%d_RotAxis_Steer.mat',k)
load(Hinge)
xdd = Data.Tibia.AccWorld;
iFreeAcc = find(strcmp(Data.Tibia.header,'FreeAcc_E')); % bij header kijken wat er allemaal instaat, vrije acceleratie E (maar dus eigenlijk ook N en U denk ik, zie hieronder)
xdd2 = Data.Tibia.data(:,iFreeAcc:iFreeAcc+2); % ik denk dat die nu FreeAcc_E, FreeAcc_N, FreeAcc_U heeft genomen dus 3 kolommen van data
% FIGURE 1 DIFFERENCE BETWEEN WITH AND WITHOUT GRAVITY
figure(1)
subplot(311); % X AS
plot(xdd(839:end,1)); hold on;
plot(xdd2(839:end,1)); hold on; % x as
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title('IMU Acc in x-direction SUP HR T02','FontSize', 8)
legend('Acc with gravity','Acc without gravity','location','northeast')
%subplot(312); % Y AS
plot(xdd(839:end,2)); hold on;
plot(xdd2(839:end,2)); hold on; % y as
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title('IMU Acc in y-direction SUP HR T02','FontSize', 8)
legend('Acc with gravity','Acc without gravity','location','northeast')
%subplot(313); % Z AS
plot(xdd(839:end,3)); hold on;
plot(xdd2(839:end,3)); hold on; % z as → probleem: bij de z: been is stil maar versnelling is niet nul want werkt in tegen de zwaartekracht want je houdt been vast - want er is een continue valversnelling, OpenSim houdt hier geen rekening mee dus we willen dit er af trekken - IMU heeft dit ook al gedaan en dat staat onder vrije acceleraties → zie figuur oranje onderste lijn, nu vertrekt die wel mooi vanaf nul omdat er 9.81 is van af getrokken
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title('IMU Acc in z-direction SUP HR T0','FontSize', 8)
legend('Acc with gravity','Acc without gravity','location','northeast')
xdd_norm = zeros(length(xdd2),1);
for f=1:length(xdd2)
xdd_norm(f) = norm(xdd2(f,:)); % gebruikt NORM FUNCTION (!!) norm(v) returns the Euclidean norm of vector v. This norm is also called the 2-norm, vector magnitude, or Euclidean length.
end
% FIGURE 2 IMU VERSNELLING NORM WAARDE
figure(2)
plot(xdd_norm(839:end)); hold on; % IMU: dit is dus de versnelling in één waarde weergegeven (frames en pendulumbeweging) → HET IS DIT DAT WE WILLEN VERGELIJKEN MET DE VERSNELLING IN OPENSIM!!
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title('IMU Norm SUP HR T02','FontSize', 8)
%%% OPENSIM %%%
% dataFolder = [startpath '/POINT KINEMATICS/'];
% dataFile = fullfile(dataFolder,['3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T' num2str(k) '_acc.sto'])
% pathwayPK_acc = dir(dataFile);
% PK_acc = importdata(fullfile(pathwayPK_acc.folder,pathwayPK_acc.name))
% PK_acc2 = PK_acc.data(:,2:4)/(10000000000);
addpath ('/MATLAB Drive/BIOMECHLISSA/POINT KINEMATICS')
if k == 1
PK_acc = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T1_acc.sto');
elseif k == 2
PK_acc = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T2_acc.sto');
elseif k == 3
PK_acc = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_UP_HR_T3_acc.sto');
elseif k == 4
PK_acc = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T4_acc.sto');
elseif k == 5
PK_acc = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T5_acc.sto');
end
PK_acc2 = PK_acc.data(:,2:4)/(10000000000);
% FIGURE 3 OPENSIM POINT KINEMATICS ACCELERATION
figure(3)
plot(PK_acc2(1091:end,:)), hold on;
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title('OPENSIM PK Acc SUP HR T02','FontSize', 8)
legend('State 0','State 1','State 2','location','northwest')
PK_acc_norm = zeros(length(PK_acc.data),1); % ook weer norm voor bepaald
for i=1:length(PK_acc.data)
PK_acc_norm(i) = norm(PK_acc2(i,1:3)); % gebruikt NORM FUNCTION (!!) norm(v) returns the Euclidean norm of vector v. This norm is also called the 2-norm, vector magnitude, or Euclidean length.
end
% FIGURE 4 OPENSIM VERSNELLING NORM WAARDE
figure(4)
plot(xdd_norm(starttimeOS:end)); hold on
plot(PK_acc_norm(starttimeIMU:end)); hold on; legend({'IMU acc norm','OpenSim PK acc norm'},'location','best');
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title('Norm acc: IMU acc vs OPENSIM PK acc SUP HR T02','FontSize', 8)
firstlengthIMU = (length(xdd_norm)) - starttimeIMU
firstlengthOPENSIM = (length(PK_acc_norm)) - starttimeOS
% FIGURE 5 CALCULATING DIFFERENCE SCORE OPENSIM AND IMU ACC NORM!! DUS
% EIGENLIJK FIGUUR 16 VERSCHIL GENOMEN
figure(5)
%subplot(5,1,k)
if firstlengthIMU > firstlengthOPENSIM
endtime = firstlengthOPENSIM + starttimeIMU
plot(PK_acc_norm(starttimeOS:end) - xdd_norm(starttimeIMU:endtime)); hold on;
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title(['Difference IMU Norm & OPENSIM PK acc SUP HR T0' num2str(k)],'FontSize', 6)
else endtime = firstlengthIMU + starttimeOS
plot(PK_acc_norm(starttimeOS:endtime) - xdd_norm(starttimeIMU:end)); hold on;
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title(['Difference IMU Norm & OPENSIM PK acc SUP HR T0' num2str(k)],'FontSize', 6)
end
addpath ('/MATLAB Drive/BIOMECHLISSA/POINT KINEMATICS')
if k == 1
PK_vel = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T1_vel.sto');
end
if k == 2
PK_vel = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T2_vel.sto');
end
if k == 3
PK_vel = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T3_vel.sto');
end
if k == 4
PK_vel = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T4_vel.sto');
end
if k == 5
PK_vel = importdata('3DGaitModel2354-scaled_PointKinematics_IMU_SUP_HR_T5_vel.sto');
end
PK_vel_diff = diff(PK_vel.data(:,2:4))/0.01;
PK_vel_diff_norm = zeros(length(PK_vel_diff),1);
for z=1:length(PK_vel_diff)
PK_vel_diff_norm(z) = norm(PK_vel_diff(z,:));
end
% FIGURE 6 IMU ACC VS OPENSIM PK DERIVATIVE OF VELOCITY
figure(6)
plot(xdd_norm(839:end)); hold on
plot(PK_vel_diff_norm(1091:end)); hold on; %DIT IS OPENSIM
legend({'IMU acc norm','OPENSIM vel diff norm'}, 'Location', "best")
title(['Norm acc: IMU acc vs OPENSIM PK derivative of velocity SUP HR T0' num2str(k)],'FontSize',7)
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
sizePKacc = size(PK_acc2) %2487
sizexddnorm = size(xdd_norm) %2133
secondlengthOPENSIM = (length(PK_vel_diff_norm)) - starttimeOS
secondlengthIMU = (length(xdd_norm)) - starttimeIMU
endtime2 = secondlengthOPENSIM + starttimeIMU
% FIGURE 7 CALCULATING DIFFERENCE SCORE OPENSIM DERIVATIVE VELOCITY AND IMU
%ACC NORM DUS EIGENLIJK FIGUUR 17 VERSCHIL GENOMEN
figure(7) %nog verschil maken van als ene langer is dan andere
%subplot(5,1,k)
if secondlengthIMU > secondlengthOPENSIM
endtime = secondlengthOPENSIM + starttimeIMU
plot(PK_vel_diff(starttimeOS:end) - xdd_norm(starttimeIMU:endtime)); hold on;
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title(['Difference IMU Norm & OPENSIM PK derivative velocity SUP HR T0' num2str(k)],'FontSize', 6)
else endtime = secondlengthIMU + starttimeOS
plot(PK_vel_diff(starttimeOS:endtime) - xdd_norm(starttimeIMU:end)); hold on;
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee acc [°/ms²]','FontSize', 8)
title(['Difference IMU Norm & OPENSIM PK derivative velocity SUP HR T0' num2str(k)],'FontSize', 6)
end
%%%%%%%%%%%%%%%%%%%% PART TWO %%%%%%%%%%%%%%%%%%%%%%%
%%% IMU %%%
addpath ('/MATLAB Drive/BIOMECHLISSA/RAW IMU')
name4 = sprintf('MATLAB Drive/BIOMECHLISSA/RAW IMU/Sup_HR_Trial0%d_data.mat',k)
load(name4)
name5 = sprintf('MATLAB Drive/BIOMECHLISSA/RAW IMU/Sup_HR_Trial0%d_RotAxis_Steer.mat',k)
load(name5)
Hinge = name5
iGyr = find(strcmp(Data.Tibia.header,'Gyr_X')); % hierin zit onze gyroscoop data dus de hoeksnelheid
qd = Data.Tibia.data(224:end,iGyr:iGyr+2); % hoeksnelheden in assenstelsel sensor % ik denk dat die nu Gyr_X, Gyr_Y, Gyr_Z heeft genomen dus 3 kolommen van data
qTest = qd*Rax'
length_qTest = length(qTest)
% FIGURE 8 IMU GYROSCOPE DATA 3 PLOTS
figure(5);
time_qtest = 0.01:0.01:length(qTest(839:end,1))/100
plot(time_qtest,-(qTest(839:end,1)*180/pi),':m'); hold on; % er worden drie roze grafieken gegeven!!! % dit kunnen we ook weer plotten
plot(time_qtest,-(qTest(839:end,2)*180/pi),'-.m');hold on;
plot(time_qtest,-(qTest(839:end,3)*180/pi),'m');hold on;
%%% OPENSIM %%%
% dataFolderBK = [startpath '/BODY KINEMATICS/'];
% dataFileBK = fullfile(dataFolderBK,['3DGaitModel2354-scaled_BodyKinematics_vel_global_SUP_HR_0' num2str(k) '.sto']);
% pathwayBK_vel = dir(dataFileBK);
% vel = importdata(fullfile(pathwayBK_vel.folder,pathwayBK_vel.name))
% vel_new = -vel.data(starttimeOS:end,17);
% time_vel = 0.01:0.01:length(vel.data(starttimeOS:end,1))/100;
addpath ('/MATLAB Drive/BIOMECHLISSA/BODY KINEMATICS')
if k == 1
vel = importdata('3DGaitModel2354-scaled_BodyKinematics_vel_global_SUP_HR_01.sto');
else
end
if k == 2
vel = importdata('3DGaitModel2354-scaled_BodyKinematics_vel_global_SUP_HR_02.sto');
else
end
if k == 3
vel = importdata('3DGaitModel2354-scaled_BodyKinematics_vel_global_SUP_HR_03.sto');
else
end
if k == 4
vel = importdata('3DGaitModel2354-scaled_BodyKinematics_vel_global_SUP_HR_04.sto');
else
end
if k == 5
vel = importdata('3DGaitModel2354-scaled_BodyKinematics_vel_global_SUP_HR_05.sto');
else
end
vel_new = vel.data(starttimeOS:end,17);
time_vel = 0.01:0.01:length(vel.data(starttimeOS:end,1))/100;
%FIGURE 9 PLOT BODY KINEMATICS VELOCITY
figure(9)
plot(time_vel,vel_new,'--r'); hold on;
addpath ('/MATLAB Drive/BIOMECHLISSA/JENTE IK')
if k == 1
IK = importdata('Sup_HR_T1.mot');
elseif k ==2
IK = importdata('Sup_HR_T2.mot');
elseif k == 3
IK = importdata('Sup_HR_T3.mot');
elseif k == 4
IK = importdata('Sup_HR_T4.mot');
elseif k == 5
IK = importdata('Sup_HR_T5.mot');
end
ka = IK.data(432:end,11);
kv = diff(ka)/0.01; % OOK OPNIEUW GAAN SYNCHRONISEREN
plot(IK.data(1:length(kv),1),-kv,'--b'); hold on;
legend('IMU Angular vel X','IMU Angular vel Y', 'IMU Angular vel Z', 'OPENSIM BK Angular vel', 'OPENSIM IK Derivative of angles','FontSize',6, 'Location', 'Northwest', 'Position',[0.7 0.7 0.1 0.2])
title('Velocities in the same coordinate system SUP HR T02','FontSize',8)
xlabel('Time [s]','Position',[12 -310],'FontSize', 8)
ylabel ('Knee vel [°/s]','Position',[-2 0],'FontSize', 8)
% FIGURE 10 CALCULATING DIFFERENCE SCORE OPENSIM IK DERIVATIVE AND IMU
%ANGULAR VELOCITY DUS EIGENLIJK FIGUUR 20 VERSCHIL GENOMEN
fourthlengthOPENSIM= (length(kv)) - starttimeOS
endtime4 = fourthlengthOPENSIM + starttimeIMU
figure(10)
%subplot(5,1,k)
plot((qTest(starttimeIMU:endtime4,1)*180/pi) - (kv(starttimeOS:end))); hold on;
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee vel [°/ms]','FontSize', 8)
title(['Difference IMU Ang vel & OPENSIM IK derivative SUP HR T' num2str(k)],'FontSize', 6)
thirdlengthOPENSIM= (length(vel_new)) - starttimeOS
endtime3 = thirdlengthOPENSIM + starttimeIMU
% FIGURE 11 CALCULATING DIFFERENCE SCORE OPENSIM BK ANGULAR VELOCITY AND IMU
%ANGULAR VELOCITY DUS EIGENLIJK FIGUUR 20 VERSCHIL GENOMEN
figure(11)
%subplot(5,1,k)
plot((qTest(starttimeIMU:endtime3,1)*180/pi) - (vel_new(starttimeOS:end))); hold on;
xlabel('Time [ms]','FontSize', 8)
ylabel ('Knee vel [°/ms]','FontSize', 8)
title(['Difference IMU Ang vel & OPENSIM BK Ang vel SUP HR T0' num2str(k)],'FontSize', 6)
end
Matt J
2021년 5월 1일
Much better, but we also cannot run the code it references files, folder paths, and data that we do not have. Please provide a modification of the code that will reproduce the issue without needing to run in your environment. It would also be a good idea if you would copy/paste the errors you are getting so we know what we should expect.
Lissa
2021년 5월 1일
Hi, thanks in advance for answering. The loop works if I just put k = 1, but I can an error when i put k = 2. Is it due to the if/else loop used for importdata?
Stephen23
2021년 5월 1일
Note that rather than using ADDPATH to dynamically add data folders to the MATLAB search path, you should just use absolute/relative filenames (hint: you will need to use FULLFILE). In general the search path should only refer to folders containing code.
Lissa
2021년 5월 1일
편집: Lissa
2021년 5월 1일
startpath = 'MATLAB Drive/BIOMECHLISSA/';
datapathvel = [startpath 'BODY KINEMATICS/'];
dataFilevel = fullfile(datapathvel,'3DGaitModel2354-scaled_BodyKinematics_vel_global_SUP_HR_0*.sto');
pathwayvel = dir(dataFilevel)
vel = importdata(fullfile(pathwayvel(k).folder,pathwayvel(k).name));
Yes, I already tried that method but was not sure how you could refer to the .data folder of the struct?
Lissa
2021년 5월 1일
clear all
close all
clc
k = 1
startpath = '/MATLAB Drive/BIOMECHLISSA/';
datapathvel = [startpath 'BODY KINEMATICS/'];
dataFilevel = fullfile(datapathvel,['3DGaitModel2354-scaled_BodyKinematics_vel_global_SUP_HR_0' num2str(k) '.sto'])
pathwayvel = dir(dataFilevel)
vel = importdata(fullfile(pathwayvel.folder,pathwayvel.name));
If I run this in a new blank scipt it works fine and the vel variable is the right struct. When I paste it in the other script it still gives the same error of dot indexing not supported for this variable ..
답변(1개)
Jan
2021년 5월 1일
vel = importdata(...)
does not create the output vel as a struct in your case. I assume ".sto" files are text files. Then the output ia a matrix.
A bold guess is tha you have to replace
vel_new = vel.data(starttimeOS:end,17);
by
vel_new = vel(starttimeOS:end,17);
댓글 수: 2
Jan
2021년 5월 1일
Please do not post code as screenshot. Posting it as text allows the readers to write an answer by copy&paste.
Your code still contains "vel.data". My suggestion was to omiut the ".data". Did you try this already?
I cannot know, what files type you import. Maybe some ate text files (which are imported as matrices) and others are MAT or XLSX files, which are imported as structs. For efficient work he command importdata is too powerful, because it tries to import the file with automagic guessing of what the user might need. This is finde for a short hack, if the user knows exactly what to do. For scientific work a specific import routine would be much safer.
By the way:
time_vel = 0.01:0.01:length(vel.data(starttimeOS:end,1))/100;
The length of the vector (vel.data(starttimeOS:end,1)) can be determined by:
size(vel.data, 1) - starttimeOD + 1;
참고 항목
범주
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다: .
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)