using element in a vector imported from workspace in simulink
###### —————– EDIT: I ADDED THE SIMULINK MODEL AND THE MATLAB FILE WHERE i SYNTHESIZED THE DATA
###### —————– EDIT2-OBJECTIVE: I’m trying to recreate the model presented in the following paper: here. I’m looking at equation (13) with k=2, and the expressions (D1) and (D2) above it. I’m also using the definition of c'(x) from equation (9) and the definition of below equation (3).
Hi,
I don’t have much experience with simulink, and I couldn’t find exactly what I was looking for online, I hope someone might help:
I have a vector x which I pass to simulink from the workspace. Now, I’m trying to implement a used defined function block:
function y = fcn(lambda, x, e1, e2)
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where lambda is calculated in the simulation in previous block (the computation is correct) and e1, e2 are scalar values of type double. I pass the parameters from the workspace as follows:
x_data.time=t’;
x_data.signals.values = x’;
e1_data.time=t’;
e1vec = repelem(e1, length(x));
e1_data.signals.values = e1vec’;
e2_data.time=t’;
e2vec = repelem(eta_dis, length(x));
e2_data.signals.values = e2vec’;
I get the following error:
Index exceeds array dimensions. Index value 0 exceeds valid range [1-1] for array ‘x’.
Error in ‘pmp_sim/MATLAB Function’ (line 3)
x = x(t);
I thought the a problem is that simulink treats these vectors as one block or something, as I read online, when I try to treat these elements in the function as vectors, meaning:
function y = fcn(lambda, x, e1, e2)
x = x(t);
e1 = e1(t);
e2 = e2(t);
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where t is the simulation clock, I get the following error:
Domain error. To compute complex results from real x, use ‘sqrt(complex(x))’.
Error in sqrt.m (line 13)
coder.internal.error(‘Coder:toolbox:ElFunDomainError’,mfilename);
Error in ‘pmp_sim/MATLAB Function’ (line 8)
can someone please explain to me how should I treat these vectors that I import to simulink model from workspace?
Thank you for you time and attention.###### —————– EDIT: I ADDED THE SIMULINK MODEL AND THE MATLAB FILE WHERE i SYNTHESIZED THE DATA
###### —————– EDIT2-OBJECTIVE: I’m trying to recreate the model presented in the following paper: here. I’m looking at equation (13) with k=2, and the expressions (D1) and (D2) above it. I’m also using the definition of c'(x) from equation (9) and the definition of below equation (3).
Hi,
I don’t have much experience with simulink, and I couldn’t find exactly what I was looking for online, I hope someone might help:
I have a vector x which I pass to simulink from the workspace. Now, I’m trying to implement a used defined function block:
function y = fcn(lambda, x, e1, e2)
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where lambda is calculated in the simulation in previous block (the computation is correct) and e1, e2 are scalar values of type double. I pass the parameters from the workspace as follows:
x_data.time=t’;
x_data.signals.values = x’;
e1_data.time=t’;
e1vec = repelem(e1, length(x));
e1_data.signals.values = e1vec’;
e2_data.time=t’;
e2vec = repelem(eta_dis, length(x));
e2_data.signals.values = e2vec’;
I get the following error:
Index exceeds array dimensions. Index value 0 exceeds valid range [1-1] for array ‘x’.
Error in ‘pmp_sim/MATLAB Function’ (line 3)
x = x(t);
I thought the a problem is that simulink treats these vectors as one block or something, as I read online, when I try to treat these elements in the function as vectors, meaning:
function y = fcn(lambda, x, e1, e2)
x = x(t);
e1 = e1(t);
e2 = e2(t);
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where t is the simulation clock, I get the following error:
Domain error. To compute complex results from real x, use ‘sqrt(complex(x))’.
Error in sqrt.m (line 13)
coder.internal.error(‘Coder:toolbox:ElFunDomainError’,mfilename);
Error in ‘pmp_sim/MATLAB Function’ (line 8)
can someone please explain to me how should I treat these vectors that I import to simulink model from workspace?
Thank you for you time and attention. ###### —————– EDIT: I ADDED THE SIMULINK MODEL AND THE MATLAB FILE WHERE i SYNTHESIZED THE DATA
###### —————– EDIT2-OBJECTIVE: I’m trying to recreate the model presented in the following paper: here. I’m looking at equation (13) with k=2, and the expressions (D1) and (D2) above it. I’m also using the definition of c'(x) from equation (9) and the definition of below equation (3).
Hi,
I don’t have much experience with simulink, and I couldn’t find exactly what I was looking for online, I hope someone might help:
I have a vector x which I pass to simulink from the workspace. Now, I’m trying to implement a used defined function block:
function y = fcn(lambda, x, e1, e2)
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where lambda is calculated in the simulation in previous block (the computation is correct) and e1, e2 are scalar values of type double. I pass the parameters from the workspace as follows:
x_data.time=t’;
x_data.signals.values = x’;
e1_data.time=t’;
e1vec = repelem(e1, length(x));
e1_data.signals.values = e1vec’;
e2_data.time=t’;
e2vec = repelem(eta_dis, length(x));
e2_data.signals.values = e2vec’;
I get the following error:
Index exceeds array dimensions. Index value 0 exceeds valid range [1-1] for array ‘x’.
Error in ‘pmp_sim/MATLAB Function’ (line 3)
x = x(t);
I thought the a problem is that simulink treats these vectors as one block or something, as I read online, when I try to treat these elements in the function as vectors, meaning:
function y = fcn(lambda, x, e1, e2)
x = x(t);
e1 = e1(t);
e2 = e2(t);
if x < sqrt(e1*lambda)
y = sqrt(e1*lambda) – x;
elseif x > sqrt((1/e2)*lambda)
y = sqrt((1/e2)*lambda) – x;
else
y = 0;
end
where t is the simulation clock, I get the following error:
Domain error. To compute complex results from real x, use ‘sqrt(complex(x))’.
Error in sqrt.m (line 13)
coder.internal.error(‘Coder:toolbox:ElFunDomainError’,mfilename);
Error in ‘pmp_sim/MATLAB Function’ (line 8)
can someone please explain to me how should I treat these vectors that I import to simulink model from workspace?
Thank you for you time and attention. matlab, simulink, vector MATLAB Answers — New Questions