現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)