How to obtain a vector (A) of 11 rows (output MATLAB Function block), from a vector (B) of 501 rows (input to the MATLAB Function block)?.

조회 수: 2 (최근 30일)
Size mismatch (size [1 x 1] ~= size [10 x 1]). The size to the left is the size of the left-hand side of the assignment. More information
% The following code corresponds to the MATALAB function block that gives an error in the Simulink model in which I am working:
function y=f(A,B)
y=sqrt((A).^2+(B).^2);
y=y(1:49:450,1)
For more information:
If I load the vectors (A y B) in workspace and run it in command windows the desired result is obtained. I need to extract vector elements in matlab function from Simulink. If this is not possible, how can I extract the elements of the vector at the output of the function without leaving Simulink?.
  댓글 수: 4
Fangjun Jiang
Fangjun Jiang 2023년 3월 22일
편집: Fangjun Jiang 2023년 3월 22일
My confusion comes from the title of your question. I thought it indicated that A has 11 rows.
By the way, y(1:49:450) should have 10 elements, not 11.
size(1:49:450)
ans = 1×2
1 10

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

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2023년 3월 22일
The straight solution is to use below.
function y=f(A,B)
temp=sqrt((A).^2+(B).^2);
y=temp(1:49:450);
Simulink is strict on knowing the size of the variable and keep it fixed (although variable size is possible).
It's better to click "edit data" at the MATLAB Function block code editor and specify the size of input, output, parameters, temp variables, etc.
  댓글 수: 8

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

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by