Number of elements mismatch.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mike Leijten
am 12 Okt. 2021
Kommentiert: Dave B
am 12 Okt. 2021
Hi everyone,
I have a dimension issue:
I have a Simulink Matlab Function block that has a [3x1] vector of values called pd as its input. This vector should turn into a [6x1] vector called pdot by adding three zeros to every element. Basically just resizing
from
to
it sounds rather simple but I can't get it to work. The code that I use in my Simulink function block is shown below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/765121/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/765126/image.png)
function pdot = fcn(pd)
pdot = zeros(6,1);
temp = zeros(6,1);
for i = 1:length(pd)
pdot(i) = temp(i) + [pd(i); 0; 0; 0];
end
end
Thanks in advance for any tips or advice.
0 Kommentare
Akzeptierte Antwort
Dave B
am 12 Okt. 2021
This seems like you maybe over complicated it? Is it as simple as...
x=[1;3;5]
fcn(x)
function pdot = fcn(pd)
pdot=[pd;0;0;0];
end
2 Kommentare
Dave B
am 12 Okt. 2021
Happy to help.
Two options:
Take the 51 x 6 and make it 6 x 1 x 51:
pdot=rand(51,6);
pdot=reshape(pdot.',6,1,51); % transpose then reshape
pd = rand(3,1,51);
pdot = padarray(pd, [3 0 0], 0, 'post'); % pad with 3 rows (0 columns, 0 in third dimension), with the value 0, padding on the 'bottom' not the 'top'
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu String finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!