Thomas Preece
Thomas Preece

Reputation: 3

Matlab changing variable type, checking not making sense

I might be doing something silly or just have a lack of understanding but I am currently working with a table of data and when I change the variable type of a column using the table.column notation when I check using the table(:,1) notation it returns a 0.

For example in my table the first column is Creditability (where table is the name of the table) so I changed the variable type using table.Creditability = logical(table.Creditability)

Then when I use islogical(table.Creditability) it returns 1

But when I use islogical(table(:,1)) it returns 0 yet when I type table(:,1) it returns a logical variable in true or false form.

I may just have a lack of understanding as I am new to this but any help would be appreciated.

Thanks

Upvotes: 0

Views: 43

Answers (1)

Pradeep Miriyala
Pradeep Miriyala

Reputation: 104

Of course it will return 0. This is because of basic point you are missing.
"table" is a structure variable in which a field named "Creditability" is created.
While "Creditability" is a logical array, it's parent "table" is still a structure.
Now, you are not getting error with statement table(:,1) although table is scalar. That is because, MATLAB treats everything as matrix.
In this case, table is 1x1 matrix.

I hope it is clear now.

Upvotes: 1

Related Questions