I am trying to create a legend key that says the name of a cell, then is followed by the value for mutual information.
Something like this:
legend(strcat('T9C11, MI =' num2str(mutualInfoTotal(67)),'T8C7','T8C5','T9C6')
But with the values for mutual information after each of the electrode names. But what I am doing now isn't working. So, what I want the legend to be like is like:
T9C11, MI = ______
T8C7, MI = ______
and so on.
Thanks!

6 件のコメント

Ruger28
Ruger28 2020 年 5 月 26 日
編集済み: Ruger28 2020 年 5 月 26 日
What is the error you are getting?
Also, if you are plotting different datasets at once, using strcat will not work for seperating the legend names.
Looping throught your data is an easy way (though not too efficient) to create the titles.
baseNames = {'T9C11','T8C7','T8C5','T9C6'};
for idx = 1:length(baseNames)
NewNames{idx} = sprintf('%s, MI = %2.2f',baseNames{idx},mutualInfoTotal(idx)) % whatever value mutualInfoTotal you need here
end
legend(NewNames)
edit: forgot to store the values into the array! Thanks, Tommy.
Mary Hemler
Mary Hemler 2020 年 5 月 26 日
Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other
syntax error. To construct matrices, use brackets instead of parentheses.
Ruger28
Ruger28 2020 年 5 月 26 日
what is the full error, and is it only erroring when you try to add the legend?
Mary Hemler
Mary Hemler 2020 年 5 月 26 日
Okay, the code you suggested won't work because the mutual information that I want to pull from is under a different variable than T9C11 (i.e., it is mutualInfoTotal(67))
Tommy
Tommy 2020 年 5 月 26 日
You can still use the same idea, just pull the pertinent values from mutualInfoTotal:
baseNames = {'T9C11','T8C7','T8C5','T9C6'};
baseValues = mutualInfoTotal([67 68 69 70]); % or whatever the indices are
NewNames = cell(numel(baseNames,1));
for idx = 1:length(baseNames)
NewNames{idx} = sprintf('%s, MI = %2.2f',baseNames{idx},baseValues(idx));
end
legend(NewNames)
(One slight addition - storing the strings in a cell array.)
Rik
Rik 2020 年 5 月 26 日
@Tommy, you should probably move this to the answer section.

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

 採用された回答

Tommy
Tommy 2020 年 5 月 27 日

0 投票

You can still use the same idea as Ruger28's comment, just pull the pertinent values from mutualInfoTotal:
baseNames = {'T9C11','T8C7','T8C5','T9C6'};
baseValues = mutualInfoTotal([67 68 69 70]); % or whatever the indices are
NewNames = cell(numel(baseNames,1));
for idx = 1:length(baseNames)
NewNames{idx} = sprintf('%s, MI = %2.2f',baseNames{idx},baseValues(idx));
end
legend(NewNames)
(Majority of code courtesy of Ruger28, who is more than welcome to post an answer, in which case I'll delete this)

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2020 年 5 月 26 日

回答済み:

2020 年 5 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by