Can I access what's in the test vector in MatLab code during Main Test?

I saw a matlab page that talked about a getValue method, but I get an error saying "Attempt to reference field of non-structure array".
I don't think I understand what TestVector is, so that I can access its contents. The help really focuses on how to create them using the wizard.
Thanks

1 件のコメント

James
James 2011 年 8 月 26 日
What I've sometimes done is created an input and signal straight to an output simply for a signal that's in the Test Vector (such as expected output), so that I can use it in a check as is appropriate. It's the easiest access I've normally found to it.

サインインしてコメントする。

 採用された回答

Bart Addis
Bart Addis 2011 年 8 月 29 日

1 投票

If you create a MATLAB element in the Main Test, you'll be able to access the test vector directly by name. It will contain the value for the current iteration.
If you create a test vector T with values [1:1:10], then in iteration 3, T will have the value 3.

3 件のコメント

James
James 2011 年 8 月 29 日
My test vectors are more complex than that. A single iteration corresponds to a single sheet of an Excel spreadsheet. Every row corresponds to a timestep within the iteration, and every column can be a piece of data (either mapped to an input port, or extra data that's just read in [this is what I want to access]).
Bart Addis
Bart Addis 2011 年 8 月 29 日
Are you using the Excel Test Vector to create these, or are you using xlsread?
James
James 2011 年 8 月 29 日
The former, the wizard claims it evaluates to a 1x1 cell but I've realised - for example - TestVector1(1,3) does give access to the third element on the first row.

サインインしてコメントする。

その他の回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 26 日

1 投票

Is your test vector data a structure? The function to get its field is called getfield(). getvalue() seems to be a different function.

12 件のコメント

James
James 2011 年 8 月 26 日
It's just what's coming from an excel spreadsheet. It says it's a 1x1 cell array - though if I read with different settings that can change.
if TestVector1.getField('Time') > 0
^^ doesn't work. The same error message.
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 26 日
It's a cell array so type TestVector1{1} in Command Window to see what is the value.
James
James 2011 年 8 月 26 日
"Cell contents reference from a non-cell array object."
When I said it was a 1x1 cell array, that's what the Test Vector wizard says it "evaluated to".
James
James 2011 年 8 月 26 日
That being an error message I quoted.
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 26 日
All right, go to Command Window, type who or whos, find the variable name for your test vector, type its name and see what you got. There are many other ways to inspect the variable, type workspace, or open('VariabeName')
Walter Roberson
Walter Roberson 2011 年 8 月 26 日
What does
class(TestVector)
report?
James
James 2011 年 8 月 29 日
erm, "??? Undefined function or variable 'TestVector1'."
The TestVector is within the SystemTest environment. MatLab code within the SystemTest environment doesn't produce output in response to commands like that (as far as I can tell anyway).
Thanks for the suggestions. The only way I've noticed to have access to the contents of the Test Vector is if it was created initially in matlab code (so contents are known), or if the data is passed through the model and read out from outputs.
James
James 2011 年 8 月 29 日
Actually, "whos" does work, though "who" doesn't.
Name Size Bytes Class Attributes
TestVector1 29x5 1160 double
James
James 2011 年 8 月 29 日
open() and class() don't work.
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
who give you a list of variables. whos gives more info such as Name, Size, etc. open('TestVector1') will open an Excel like interface for you to view and edit value. class(TestVector1) will return double.
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
Your TestVector1 is an ordinary 2-D double array. To access it, just type TestVector1 in Command Window and you'll see the value. To access individual element, use TestVector1(3,2) for example.
James
James 2011 年 8 月 29 日
If you want to access SystemTest variables from the Command Window you need to use:
stresults.ResultsDataSet; // used after a test
// or
obj = systest.testresults.getCurrent;
currentResults = obj.ResultsDataSet; // used during a test
If you hadn't realised, I'm not trying to access it in the Command Window - but in a SystemTest Matlab code element.

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by