Help with linear optimisation problem
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi folks,
I'm looking to conduct a linear optimisation and was hoping for some help on the matter.
I have 56 columns of data, with 256 rows each; lets call this set A. I have another column of data, with 56 rows; lets call this set B. I essentially want to correlate each of the 256 values in each column of set A to a single value in set B; lets call this set C.
I want to know which of the 256 values across set C give the best correlation between sets A and B. In other words, which row in set A gives the best correlation to the corresponding value in set B, across all columns of set A.
Any help on this matter would be most appreciated!
採用された回答
Diffs=abs(reshape(B,1,1,[])-A);
d=min(Diffs,[],3);
[Arows,Acols]=find(d==min(d(:)));
11 件のコメント
Teshan Rezel
2022 年 1 月 25 日
@Matt J Hi, thanks for this! I'm just having an issue with the first line of your code as it says reshape doesn't work on tables...any ideas on how I can get around this please?
Matt J
2022 年 1 月 25 日
You can use table2array to convert them to ordinary matrices.
Teshan Rezel
2022 年 1 月 25 日
@Matt J Thank you! I tried that but now it throws out this error, although my data is in tables, not cells!
Operator '-' is not supported for operands of type 'cell'.
Matt J
2022 年 1 月 25 日
My solution assumes all variables are numeric matrices. If this isnt' the case for one/all of your variables, you need to convert them appropriately.
Teshan Rezel
2022 年 1 月 25 日
@Matt J I've made sure that all values in the tables are numeric, but it now says :
Error using tabular/reshape (line 216)
Undefined function 'reshape' for input arguments of type 'table'.
I'm not sure what's causing this now!
I've made sure that all values in the tables are numeric
Again, they shouldn't be tables. They should be matrices. To convert tables to matrices, see table2array() which I mentioned earlier.
Teshan Rezel
2022 年 1 月 31 日
Matt J
2022 年 1 月 31 日
What about A?
Teshan Rezel
2022 年 1 月 31 日
A=load('inputVariables').sum_Coke;
B=load('inputVariables').CRI;
B=B.CRI;
whos A B
Name Size Bytes Class Attributes
A 256x54 110592 double
B 54x1 432 double
Diffs=abs(reshape(B,1,1,[])-A);
d=min(Diffs,[],3);
[Arows,Acols]=find(d==min(d(:)));
whos Arows Acols
Name Size Bytes Class Attributes
Acols 84x1 672 double
Arows 84x1 672 double
Teshan Rezel
2022 年 1 月 31 日
@Matt J outstanding, thank you!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
