Is there difference between using "data" and "[data]" when importing excel data

1 次查看(过去 30 天)
Hi All,
New to Matlab community. I am trying to import an Excel spreadsheet into Matlab using xlsread command, and store it as a numerical matrix. I am debating using either Data = xslread(sample.xlsx) or [Data] = xlsread(smple.xlsx)
I tried both commands and both seem to work. But I'd like to know, if there is any subtle difference.

采纳的回答

Walter Roberson
Walter Roberson 2018-4-10
编辑:Walter Roberson 2018-4-11
There is no difference.
[location] = value
is exactly the same as
location = value
when the location designates a single destination. Skipping the [] is effectively an abbreviation.
However if there are two output destinations such as
[row, col] = find(magic(9) == 7)
then you cannot skip the [] -- it is not valid to write, for example,
row, col = find(magic(9) == 7)
Or rather such a thing would mean to display row and then to assign the output of the find() to col.
Things can get slightly tricky if the location secretly designates a field of a non-scalar structure:
location.field = value
is valid if location is a scalar structure but not if location is a non-scalar structure. For non-scalar structures you need
[location.field] = value
Even though syntactically you cannot tell this apart from the case where location is a scalar structure, the [] are important. This is because if location is an existing non-scalar structure, then location.field triggers structure expansion into a comma separated list, as if you had written
location(1).field, location(2).field, ... location(end).field
and then under the rule that the [] is mandatory for multiple left-hand sides, you need the []
This can take some getting accustomed to.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Language Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by