How to store a string data into an array

1 回表示 (過去 30 日間)
Janrex Pensader
Janrex Pensader 2018 年 12 月 9 日
コメント済み: Janrex Pensader 2018 年 12 月 9 日
I have a an array like this:
trainLabels = zeros(315,1);
And I would like to put a string for example 'bass' on every element of that array. I tried using
fold = 'bass';
testLabels(testctr,1) = fold;
but its giving me this error:
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 1-by-4.

回答 (1 件)

madhan ravi
madhan ravi 2018 年 12 月 9 日
trainLabels = cell(315,1);
trainLabels(:)={'bass'}
  15 件のコメント
madhan ravi
madhan ravi 2018 年 12 月 9 日
To be frank and honest I don't have any experience with that field but in the link you suggested cell arrays ahd been used , why not try it and find it out?
Janrex Pensader
Janrex Pensader 2018 年 12 月 9 日
It didnt work it cause an error it shows "Invalid training data. Y must be a vector of categorical responses." where y is the trainingLabels

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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by