フィルターのクリア

How would I turn this structure array into a matrix

11 ビュー (過去 30 日間)
Brian Leon
Brian Leon 2020 年 4 月 15 日
コメント済み: Ameer Hamza 2020 年 4 月 15 日
I tried this, but i got an error
A = ([topTenWords.word],[topTenWords.frequency])

回答 (2 件)

Ameer Hamza
Ameer Hamza 2020 年 4 月 15 日
編集済み: Ameer Hamza 2020 年 4 月 15 日
If you want to have different data types then you need to use cell array
A = [{topTenWords.word}' {topTenWords.frequency}']
If you want to save as matrix, you need to use seperate variables
A_word = {topTenWords.word}';
A_freq = [topTenWords.frequency];
  6 件のコメント
Brian Leon
Brian Leon 2020 年 4 月 15 日
This code doesnt order the bar plot from highest frequency to lowest frequency, from left to right. This was my output.
Ameer Hamza
Ameer Hamza 2020 年 4 月 15 日
I think that the vector [topTenWords.frequency] is not always sorted. try this.
A_word = categorical({topTenWords.word}');
A_freq = [topTenWords.frequency];
[A_freq, idx] = sort(A_freq, 'descend');
A_word = A_word(idx);
ax = subplot(1,2,2);
bar(A_word, A_freq, 'FaceColor',[0.8500 0.3250 0.0980])
title('Most Frequent Words')
ylabel('Word Frequenices')
ax.XAxis.Categories = A_word;
xtickangle(90)

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


Star Strider
Star Strider 2020 年 4 月 15 日
編集済み: Star Strider 2020 年 4 月 15 日
EDIT — (15 Apr 2020 at 18:51)
Try this:
D3 = load('topTenWords.mat');
word = cellfun(@(x)x, {D3.topTenWords.word}, 'Uni',0)
frequency = cellfun(@(x)x, {D3.topTenWords.frequency});
figure
bar(frequency)
set(gca, 'XTickLabel',word, 'XTickLabelRotation',30)
producing:

カテゴリ

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