I need help to figure out why these variables aren't being found.
9 次查看(过去 30 天)
显示 更早的评论
DJ V
2024-10-16
I have written simulink code that is to produce variables that later are to be read into Matlab. Unfortunately, Matlab interprets those variables using the following errors:
>> EqnsOfMotionback
Warning: Variable 'pn' not found.
> In EqnsOfMotionback (line 95)
Warning: Variable 'pe' not found.
> In EqnsOfMotionback (line 96)
Warning: Variable 'pd' not found.
> In EqnsOfMotionback (line 97)
Warning: Variable 'phi' not found.
> In EqnsOfMotionback (line 98)
Warning: Variable 'psi' not found.
> In EqnsOfMotionback (line 99)
Warning: Variable 'theta' not found.
> In EqnsOfMotionback (line 100)
Why are all these variables not being found? I put them in a specific directory on purpose. I don't want to leave it to a computer's whim or some vaguely known "rule".
采纳的回答
Walter Roberson
2024-10-16
load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pn.mat","pn");
load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pe.mat","pe");
load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pd.mat","pd");
load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\phi.mat","phi");
load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\psi.mat","psi");
load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\theta.mat","theta");
The warning messages are telling you that pn is not being found in Pn.mat, and pe is not being found in Pe.mat and so on.
Possibly the variables are named Pn and Pe in the .mat files.
20 个评论
Walter Roberson
2024-10-16
In each case, the stored variable name in the .mat file is ans
pn = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pn.mat","ans").ans;
pe = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pe.mat","ans").ans;
and so on.
DJ V
2024-10-17
Okay, I used the code you recommended above.
Now when I try to print out the contents of Pn.mat on the screen by entering pn, it won't recognize the variable. Do I need to use Pn? How do I screen print the contents of Pn after the above commands? Thank you.
Walter Roberson
2024-10-17
After you use
pn = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pn.mat","ans").ans;
then you could display the contents of variable pn by entering
pn
or
disp(pn)
DJ V
2024-10-17
移动:Torsten
2024-10-17
Doesn't seem to work. All I get back from the software is:
>> EqnsOfMotionback
timeseries with properties:
Events: []
Name: ''
UserData: []
Data: [101×1 double]
DataInfo: [1×1 tsdata.datametadata]
Time: [101×1 double]
TimeInfo: [1×1 tsdata.timemetadata]
Quality: []
QualityInfo: [1×1 tsdata.qualmetadata]
IsTimeFirst: 1
TreatNaNasMissing: 1
Length: 101
timeseries
Common Properties:
Name: ''
Time: [101x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [101x1 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
pe =
struct with fields:
pe: [1×1 timeseries]
pd =
struct with fields:
pd: [1×1 timeseries]
timeseries
Common Properties:
Name: ''
Time: [101x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [101x1 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
timeseries
Common Properties:
Name: ''
Time: [101x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [101x1 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
timeseries
Common Properties:
Name: ''
Time: [101x1 double]
TimeInfo: [1x1 tsdata.timemetadata]
Data: [101x1 double]
DataInfo: [1x1 tsdata.datametadata]
More properties, Methods
Undefined function 'cos' for input arguments of type 'timeseries'.
Error in EqnsOfMotionback>rotate (line 213)
0, cos(phi), -sin(phi);
Error in EqnsOfMotionback>drawPlaneBody (line 143)
NED = rotate(NED, phi, theta, psi);
Error in EqnsOfMotionback (line 113)
handle = drawPlaneBody(pn(k),pe(k),pd(k),phi(k),theta(k),psi(k),handle);
>>
Walter Roberson
2024-10-17
Those messages appear to be correct. The data stored in the .mat files is timeseries data.
I notice that some of your variables are turning out as struct . You should be using
pn = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pn.mat","ans").ans;
pe = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pe.mat","ans").ans;
pd = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pd.mat","ans").ans;
phi = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\phi.mat","ans").ans;
psi = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\psi.mat","ans").ans;
theta = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\theta.mat","ans").ans;
That will load each of the data as timeseries objects.
As timeseries objects, there is a Time field and a Data field. The Time fields are not generally guaranteed to be uniform intervals; however, you did configure fixed-timestep ode4 solver, so the Time fields will be uniform intervals in your case.
In all of the files I examined, the Data field is uniformly 0.
DJ V
2024-10-17
So if I want to access the first entry in the pe data set is that then referenced as pe(1,1) to produce the time with the magnitude of the data as pe(1,2)?
Many, many thanks.
Del Ventruella
Walter Roberson
2024-10-17
pe.Time(1) %first Time for pe data
pe.Data(1) %ffirst Data for pe data
plot(pe.Time, pe.Data) %it's all zeros
DJ V
2024-10-18
移动:Walter Roberson
2024-10-18
Okay, I'm having some trouble with the following code. It says:
Error in EqnsOfMotionback (line 95)
Pd = load("C:\Users\1537268928E\OneDrive - United States Air
Force\Desktop\Pd.mat", "ans").ans;
>> EqnsOfMotionback
Index in position 2 exceeds array bounds (must not exceed 1).
Error in EqnsOfMotionback (line 99)
pn=Pn.Data(1,200);
The code that this generally applied to is:
handle=[];
Pn = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pn.mat", "ans").ans;
Pe = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pe.mat", "ans").ans;
Pd = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pd.mat", "ans").ans;
Phi = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\phi.mat","ans").ans;
Psi = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\psi.mat","ans").ans;
Theta = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\theta.mat","ans").ans;
pn=Pn.Data(1,200);
pe=Pe.Data(1,200);
pd=Pd.Data(1,200);
phi=Phi.Data(1,200);
psi=Psi.Data(1,200);
theta=Theta.Data(1,200);
How can I reference individual elements of pn (from 1 to 200) if I can only enter 1 in the parenthesis?
Sorry, I'm new to this. It been a decade since I last used Matlab.
Thanks a lot.
Del Ventruella
Walter Roberson
2024-10-18
The Data property is a column vector, not a row vector. Either use
pn=Pn.Data(200,1);
or use
pn=Pn.Data(200);
DJ V
2024-10-18
移动:Voss
2024-10-18
Okay, I need to know why this is only producing 100 data points. The simulation is 20 seconds long, and I thought I'd set it up with a 0.1 second interval between points. That should produce 200 points. I'll insert the simulink file. Any help with this one?
Thanks.
Del Ventruella
DJ V
2024-10-18
I've been working on this all day. I now have a simulink file that seems to work, but the Matlab file is producing errors. Those errors are the following.
>> EqnsOfMotionback
Index exceeds the number of array elements (1).
Error in EqnsOfMotionback (line 112)
handle = drawPlaneBody(pn(k),pe(k),pd(k),phi(k),theta(k),psi(k),handle);
I'd really appreciate an explanation of how to fix this in part because I don't know my way around these programs yet. Thank you very much for walking me through these errors.
Thank you.
Del Ventruella
Walter Roberson
2024-10-18
You want
pn=Pn.Data;
pe=Pe.Data;
pd=Pd.Data;
phi=Phi.Data;
psi=Psi.Data;
theta=Theta.Data;
DJ V
2024-10-18
移动:Walter Roberson
2024-10-18
Okay, that worked. How will I know how many elements are being stored under the various variables? Will it be 200, 201, or another number?
sizeof(pn)?
Thank you.
Sincerely,
Del Ventruella
Walter Roberson
2024-10-18
length(pn) will tell you how many elements were stored in pn. Or numel(pn) if you want to be more certain.
Walter Roberson
2024-10-18
编辑:Walter Roberson
2024-10-18
Please posts your responses as comments (click on "Comment on this answer"), rather than using Answer this question
DJ V
2024-10-21
移动:Voss
2024-10-21
Another question. If I use a division block, there are two inputs. One is marked with a multiplication symbol, the other with a division symbol.
Does the input the multiplication symbol serve as the numerator and the input to the division symbol serve as the denominator if the process followed by the division block were represented as a fraction?
Thank you!
SIncerely,
Del Ventruella
Walter Roberson
2024-10-21
移动:Voss
2024-10-21
There is an implicit "1" to start with. The 1 is multiplied by the inputs that are marked as multiplication, and is divided by inputs that are marked as division. For example you could have two divisions A and B, and that would be (1/A) * (1/B)
DJ V
2024-10-22
移动:Voss
2024-10-22
Now, more fun. I'm trying to control the direction of motion of the aircraft, but it seem that when I do this, I move it off the screen instantly. The errors it is outputting are as follows:
Error using matlab.graphics.chart.primitive.Line/set
Invalid or deleted object.
Error in EqnsOfMotionback>drawPlaneBody (line 166)
set(handle, 'XData', XYZ(1,:), 'YData',XYZ(2,:), 'ZData',XYZ(3,:));
Error in EqnsOfMotionback (line 117)
handle =
drawPlaneBody(pn(k),pe(k),pd(k),phi(k),theta(k),psi(k),handle);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 General Applications 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)