フィルターのクリア

Table Multiplication error: Both tables must have the same variables

90 ビュー (過去 30 日間)
Scott
Scott 2023 年 8 月 25 日
コメント済み: Scott 2023 年 8 月 27 日
I am trying to figure out why these table columns will not multiply together. It is a table of one size of imaginary numbers 94x3
SAI =
94×3 table
Var1 Var2 Var3
_________ _________ _________
0-10059i 0-5021.2i 0-3338.1i
0-8800.5i 0-4390.5i 0-2916.2i
0-7821.1i 0-3899.7i 0-2587.6i
0-7037.5i 0-3506.6i 0-2324.3i
0-6396.2i 0-3184.7i 0-2108.3i
etc...
I am getting an error when doing SAI(:,1) .*SAI(:,2).
It gives the same error when using *
Error using .*
Both tables must have the same variables.
What am I doing wrong here?
Thanks for any help
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 8 月 25 日
Any particular reason why you are storing numeric data in a table?
Or are you importing the data via readtable? If you are, I would suggest you to import numeric data via readmatrix and perform any operations on the numeric arrays accordingly.
Multiplying the columns of a table seems un-intuitive (atleast to me)
Scott
Scott 2023 年 8 月 27 日
That makes alot of sense of why I was getting some errors much appreciated

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

採用された回答

Stephen23
Stephen23 2023 年 8 月 25 日
編集済み: Stephen23 2023 年 8 月 25 日
One simple solution is to use curly braces to access table content (not parentheses which return another table):
SAI{:,1} .*SAI{:,2}
% ^ ^ ^ ^
How to access table content is explained in the documentation:
Most likely using numeric arrays would be even better, as Dyuman Joshi suggested.
"What am I doing wrong here?"
Parentheses returns a table. Your parenthesis indexing returns two tables, each of which has exactly one column/variable. But the names of those variables are different. But tables can only be operands to an operation if they have exactly the same variable names, as the documentation makes clear:
Because your two tables have different variable/column names your code throws an error.
Solution: don't try to multiply tables with different variable names.
  2 件のコメント
Scott
Scott 2023 年 8 月 27 日
Thank you!
Dyuman Joshi
Dyuman Joshi 2023 年 8 月 27 日
Hello @Scott , if this answer solved your problem, please consider accepting the answer.
Accepting the answer indicates that your problem has been solved (which can be helpful to other people in future) and it awards the volunteer with reputation points for helping you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by