You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
I need help to figure out why these variables aren't being found.
5 views (last 30 days)
Show older comments
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".
Accepted Answer
Walter Roberson
on 16 Oct 2024
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 Comments
Walter Roberson
on 16 Oct 2024
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
on 17 Oct 2024
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
on 17 Oct 2024
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
on 17 Oct 2024
Moved: Torsten
on 17 Oct 2024
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
on 17 Oct 2024
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
on 17 Oct 2024
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
on 17 Oct 2024
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
on 18 Oct 2024
Moved: Walter Roberson
on 18 Oct 2024
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
on 18 Oct 2024
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
on 18 Oct 2024
Moved: Voss
on 18 Oct 2024
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
on 18 Oct 2024
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
on 18 Oct 2024
You want
pn=Pn.Data;
pe=Pe.Data;
pd=Pd.Data;
phi=Phi.Data;
psi=Psi.Data;
theta=Theta.Data;
DJ V
on 18 Oct 2024
Moved: Walter Roberson
on 18 Oct 2024
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
on 18 Oct 2024
length(pn) will tell you how many elements were stored in pn. Or numel(pn) if you want to be more certain.
Walter Roberson
on 18 Oct 2024
Edited: Walter Roberson
on 18 Oct 2024
Please posts your responses as comments (click on "Comment on this answer"), rather than using Answer this question
DJ V
on 21 Oct 2024
Moved: Voss
on 21 Oct 2024
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
on 21 Oct 2024
Moved: Voss
on 21 Oct 2024
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
on 22 Oct 2024
Moved: Voss
on 22 Oct 2024
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);
More Answers (0)
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)