vector notation with data from struct array

조회 수: 3 (최근 30일)
Benjamin Pommer
Benjamin Pommer 2022년 3월 21일
편집: Matt J 2022년 3월 22일
I have the following problem: I want to operate with variables from my workspace which I saved in a struct array. This will be the argument for a self defined function which you can see in the following:
t_abtast = 2;
data = load('GMapsRoute02182022095722SimulationRun.mat')
v = data.GMapsRoute02182022095722SimulationRun.velocity_kmh(1:10:end)';
a = data.GMapsRoute02182022095722SimulationRun.acc(1:10:end)';
t = data.GMapsRoute02182022095722SimulationRun.t(1:10:end);
E = data.GMapsRoute02182022095722SimulationRun.energy(1:10:end)';
v = v(~isnan(v));
a = a(~isnan(a));
E = E(~isnan(E));
v = smooth(v);
a = smooth(a);
E = smooth(E);
v = v(1:t_abtast:end);
a = a(1:t_abtast:end);
t = t(1:t_abtast:end);
E = E(1:t_abtast:end);
t_delta = t(2)-t(1);
P = [0, diff(E)/t_delta];
adot = [0, diff(a)/t_delta];
[A,B,X,Y,y,res,x_vec,x_pred,u_pred] = DMDc1(5,10,4,v,a,adot,P);
...
I get this error message:
Error using horzcat
Dimensions of arrays
being concatenated are
not consistent.
Error in DMD_Prediction
(line 42)
P = [0
diff(E)/t_delta];
Before I loaded the variables with the evalin function and there was not problem.
load('GMapsRoute02182022095722SimulationRun.mat')
v = evalin('base','GMapsRoute02182022095722SimulationRun.velocity_kmh');
a = evalin('base','GMapsRoute02182022095722SimulationRun.acc');
t = evalin('base','GMapsRoute02182022095722SimulationRun.t');
E = evalin('base','GMapsRoute02182022095722SimulationRun.energy');
When I change the notation from "," to ";", I receive the following error:
Unable to perform assignment because the size of the left side is 4-by-239
and the size of the right side is 972-by-0.
Error in DMDc1 (line 71)
X((ii-1)*states+1:ii*states,:) = y(:,ii:end-n+ii);
Error in DMD_Prediction (line 47)
[A,B,X,Y,y,res,x_vec,x_pred,u_pred] = DMDc1(5,10,4,v,a,adot,P);
So, this rewriting leads to problem later in the code.

채택된 답변

Matt J
Matt J 2022년 3월 22일
Error in DMD_Prediction (line 42)
P = [0
diff(E)/t_delta];
In all likelihood diff(E) is not a row vector. THat should be easy to check.
  댓글 수: 2
benjamin pommer
benjamin pommer 2022년 3월 22일
Thank you. I could solve it
Matt J
Matt J 2022년 3월 22일
편집: Matt J 2022년 3월 22일
You're welcome, but please Accept-click the answer if it resolved your question.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by