Borrar filtros
Borrar filtros

Expected input number ... to be an array with number of columns equal to ... Simulink

36 visualizaciones (últimos 30 días)
Hi, i want to implement a internal function of MATLAB into a simulink but it gives an error.
The related function is below.
But it gives an error which ı added at end. Any ideas how could ı fix it ?
function xyzNED = lla2ned_custom( lla, lla0, method)
% lla2ned Transform geodetic coordinates to local North-East-Down coordinates
% xyzNED = lla2ned(lla, lla0, method) transforms the geodetic coordinates, lla,
% to local North-East-Down (NED) Cartesian coordinates, xyzNED. Specify
% the geodetic coordinates either as a 3-element row vector or an N-by-3
% matrix of [lat, lon, alt]. Specify the origin of the local NED system
% with the geodetic coordinates, lla0, as a 3-element row vector or an
% N-by-3 matrix of [lat0, lon0, alt0]. The conversion method is specified
% either as 'flat' or 'ellipsoid', to specify if earth is assumed to be
% flat or ellipsoidal. The local NED coordinates are returned as a
% 3-element row vector or an N-by-3 matrix of [xNorth, yEast, zDown] in
% meters. lat and lat0 specify the latitude in degrees. lon and lon0
% specify the longitude in degrees. alt and alt0 specify the
% altitude in meters.
%
% Notes
% -----
% - The latitude and longitude values in the geodetic coordinate system
% uses WGS84 standard.
% - Altitude is specified as height in meters above WGS84 reference
% ellipsoid.
%
% Limitations of the Flat Earth approximation
% -------------------------------------------
% - This transformation assumes the vehicle moves in parallel to the
% earth's surface.
%
% - This transformation method assumes the flat Earth z-axis is normal to
% the Earth at the initial geodetic latitude and longitude only. This
% method has higher accuracy over small distances from the initial
% geodetic latitude and longitude, and nearer to the equator. The
% longitude will have higher accuracy when there are smaller variations
% in latitude.
%
% - Latitude values of +90 and -90 may return unexpected values because of
% singularity at the poles.
%
% Example:
%
% %Define the geodetic coordinates
% lla=[45.976,7.658,4531];
%
% %Define the reference geodetic coordinates
% lla0=[46.017 7.750 1673];
%
% %Transform from geodetic to local NED coordinates using flat earth
% %approximation
% xyzNED = lla2ned(lla, lla0, "flat");
%
% See also lla2enu, enu2lla, ned2lla
% Copyright 2020 The MathWorks, Inc.
% References
% ----------
% - [1] Stevens, B. L., and F. L. Lewis, Aircraft Control and Simulation,
% Second Edition, John Wiley & Sons, New York, 2003.
%
% - [2] Hofmann-Wellenhof, Bernhard, Herbert Lichtenegger, and James Collins.
% Global positioning system: theory and practice. Springer Science &
% Business Media, 2012.
%
%#codegen
narginchk(3,3);
validateattributes(lla, {'double'}, {"real", "nonempty", "2d", "ncols", 3}, "lla2ned", 'lla', 1);
validateattributes(lla0, {'double'}, {"real", "nonempty", "2d", "ncols", 3}, "lla2ned", 'lla0', 2);
method=validatestring(method, {'flat', 'ellipsoid'}, "lla2ned", "method", 3);
%Verify that the inputs are within the range
matlabshared.internal.latlon.validateLat(lla0(:,1),0);
matlabshared.internal.latlon.validateLat(lla(:,1),1);
matlabshared.internal.latlon.validateLon(lla0(:,2),0);
matlabshared.internal.latlon.validateLon(lla(:,2),1);
%Verify that input matrix sizes are correct
[minSize, idx]=min([size(lla,1), size(lla0,1)]);
if minSize~=1 && size(lla,1)~=size(lla0,1)
if idx==1
coder.internal.error("shared_coordinates:latlonconv:IncorrectllaSize");
else
coder.internal.error("shared_coordinates:latlonconv:Incorrectlla0Size");
end
elseif size(lla,1)==size(lla0,1)
idx=0;
end
if idx==1
llatmp=repmat(lla,size(lla0,1),1);
lla0tmp=lla0;
elseif idx==2
lla0tmp=repmat(lla0,size(lla,1),1);
llatmp=lla;
else
llatmp=lla;
lla0tmp=lla0;
end
xyzNED=nan(size(lla0tmp,1),3);
switch method
case "ellipsoid"
%Transform to xyz in NED frame using [2]
xyzNED=[fusion.internal.frames.lla2ned(llatmp, lla0tmp)];
case "flat"
%Transform to xyz in NED frame using [1]
xyzNED = [matlabshared.internal.latlon.lla2nedFlat(llatmp, lla0tmp)];
end
%
%
% wgs84 = wgs84Ellipsoid('kilometer');
%
% lat0 = 44.532;
% lon0 = -72.782;
% h0 = 1.699;
%
% x = 1345.660;
% y = -4350.891;
% z = 4452.314;
%
%
% xNorth = 1.3343;
% yEast = -2.5444;
% zDown = 0.3600;
%
% [xNorth,yEast,zDown] = ecef2ned(x,y,z,lat0,lon0,h0,wgs84)
%
% % [x,y,z] = ned2ecef(xNorth,yEast,zDown,lat0,lon0,h0,wgs84)
%%%%%%%%%%%%%%%%%%%%%%ERROR%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expected input number 1, lla, to be an array with number of columns equal to 3.
Function 'MATLAB Function' (#250.2602.2698), line 71, column 5:
"validateattributes(lla, {'double'}, {"real", "nonempty", "2d", "ncols", 3}, "lla"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Expected input number 2, lla0, to be an array with number of columns equal to 3.
Function 'MATLAB Function' (#250.2705.2803), line 73, column 5:
"validateattributes(lla0, {'double'}, {"real", "nonempty", "2d", "ncols", 3}, "ll"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
Expected input number 3, method, to match one of these strings: 'flat', 'ellipsoid'. The input did not match any of the valid strings. Expected input to be one of these types: char, string. Instead its type was double.
Function 'MATLAB Function' (#250.2817.2886), line 75, column 12:
"validatestring(method, {'flat', 'ellipsoid'}, "lla2ned", "method", 3)"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
More information
Function 'MATLAB Function' (#250.3107.3108), line 80, column 53:
"2"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
More information
Function 'MATLAB Function' (#250.3165.3166), line 81, column 52:
"2"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'method'. The first assignment to a local variable determines its class.
Function 'MATLAB Function' (#250.3862.3868), line 108, column 12:
"method"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
More information
Function 'lla2ecef.m' (#102.804.805), line 27, column 23:
"2"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed.
Function 'lla2enu.m' (#103.914.953), line 28, column 15:
"fusion.internal.frames.lla2ecef(llaPos)"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed.
Function 'lla2ned.m' (#104.913.956), line 28, column 14:
"fusion.internal.frames.lla2enu(llaPos,lla0)"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed.
Function 'MATLAB Function' (#250.3956.4005), line 111, column 16:
"[fusion.internal.frames.lla2ned(llatmp, lla0tmp)]"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Index expression out of bounds. Attempted to access element 2. The valid range is 1-1.
More information
Function 'lla2nedFlat.m' (#105.522.523), line 17, column 18:
"2"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed.
Function 'MATLAB Function' (#250.4091.4150), line 114, column 18:
"[matlabshared.internal.latlon.lla2nedFlat(llatmp, lla0tmp)]"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'dfsgdfsgsdfgdfsgdfsgdsgdsgds/MATLAB Function'
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'dfsgdfsgsdfgdfsgdfsgdsgdsgds/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'dfsgdfsgsdfgdfsgdfsgdsgdsgds/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
Error in port widths or dimensions. 'Output Port 1' of 'dfsgdfsgsdfgdfsgdfsgdsgdsgds/MATLAB Function/method' is a one dimensional vector with 1 elements.
Component:Simulink | Category:Model error

Respuestas (1)

Subash Mylraj
Subash Mylraj el 31 de Jul. de 2023
Hi!
As per my understanding, you are facing issues with running a Simulink model that has a custom MATLAB function.
On reproducing and investigating your model, I could see that the error occurs due a validation of the attributes in the custom MATLAB function:
validateattributes(lla, {'double'}, {"real", "nonempty", "2d", "ncols", 3}, "lla2ned", 'lla', 1);
The constant array being passed to the function has a size of 3x1 which can be seen in the diagnostic report. The reason for this is due to the constant array being interpreted as a 1-D vector.
You can solve this by disabling the “Interpret vector parameters as 1-D” option in the constant block as shown in the screenshot below:
For more information on you can refer to the following MathWorks documentation:
I hope this solves your issue!
Regards,
Subash Mylraj,
MathWorks Technical Support

Categorías

Más información sobre Aerospace Applications en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by