The table, it exists, will be created by using the command "table". It has columns of both numerican values and strings.
How do I check if the table exists? I tried to use the command exist:
if ~exist(app.T1, 'class')
but it keeps complaining with the below error message:
Error using exist
The first input to exist must be a string scalar or character vector.

 Akzeptierte Antwort

Turlough Hughes
Turlough Hughes am 8 Dez. 2019
Bearbeitet: Turlough Hughes am 8 Dez. 2019

1 Stimme

If you have a table assigned to the variable T, then I believe you just need to write:
if ~exist('T')==1
to check that it doesn't exist. The error was that you inputted the actual variable as opposed to a string/character vector representing the name of the variable.

5 Kommentare

Leon
Leon am 8 Dez. 2019
Thanks.
Unfortunately, it did not work.
This is within app-designer, so I used the below. Matlabe seems to think it is always true whether the table exists or not.
if ~exist('app.T1')
Turlough Hughes
Turlough Hughes am 9 Dez. 2019
Bearbeitet: Turlough Hughes am 9 Dez. 2019
Try
~isprop(app,'T1')
Leon
Leon am 9 Dez. 2019
Unfortunately, it did not work.
Many thanks!
Walter Roberson
Walter Roberson am 9 Dez. 2019
My understanding of app designer is that unless you use dynamic properties, the name T1 will exist in app, but it might be empty. I suggest exploring with isfield() and isprop() and isempty()
Leon
Leon am 9 Dez. 2019
isempty(app.T1)
works.
Many thanks!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

dpb
dpb am 8 Dez. 2019

0 Stimmen

"...will be created by using the command "table"..."
So, there then has to be a variable name on the LHS of the table() statement; that variable name is what you put into the argument list for exist().
If your code creates it, how can it not exist...or is this a test first, create if not yet have done so kind of thing? That could make some sense but same caveat applies unless using the (ugh!) kludge of dynamic naming (and in the hope you don't even know what that is yet, I'm not going to explain it any further! :) ).

1 Kommentar

Leon
Leon am 8 Dez. 2019
Thanks! This is in a GUI interface within app-designer. It is one of the buttons that users can click. In rare cases if a user clicks the button before a table is generated, the program needs to have an error message for them. It certainly can not always assume a table has existed.

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2019b

Tags

Gefragt:

am 8 Dez. 2019

Kommentiert:

am 9 Dez. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by