Clear Filters
Clear Filters

vector notation with data from struct array

2 views (last 30 days)
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.

Accepted Answer

Matt J
Matt J on 22 Mar 2022
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 Comments
Matt J
Matt J on 22 Mar 2022
Edited: Matt J on 22 Mar 2022
You're welcome, but please Accept-click the answer if it resolved your question.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!