フィルターのクリア

Convert a cell array into matrix, but with just removing the commas (Need words to stay)

2 ビュー (過去 30 日間)
Okay, so it turns out that I need to keep 'known' and 'free', but I can't seem to get this to work out for me. I'm still filtering through the same NF_array (which can be changed based on user input), but now I'm trying to keep the known and free in the matrix. Below is what I'm trying to do... Thanks for the help.
NF_array = [{'1, known, known, 0.0, 0.0'}, ...
{'8, known, known, 0.0, 0.0'}, ...
{'4, free, known, 0.0, 0.0' }, ...
{'5, free, known, 0.0, 0.0' }];
%Code I'm trying to use
syms known free %defining known and free in the program
NF_array = S(NF_2:NL_2);
optf = {'Delimiter',',', 'CollectOutput',true};
fmtf = '%f%s%s%f%f';
strf = sprintf('%s\n',NF_array{:});
outf = textscan(strf,fmtf,optf{:});
Nodal_Fixity = outf{1};
Nodal_Fixity = sortrows(Nodal_Fixity)
%What I'm getting... So I need columns 2:5 to populate still
Nodal_Fixity =
1
4
5
8
%(Need the code to process NF_array and convert to)%
Nodal_Fixity =
[ 1, known, known, 0, 0]
[ 4, known, known, 0, 0]
[ 5, free, known, 0, 0]
[ 8, free, known, 0, 0]
  2 件のコメント
Damon Schmidt
Damon Schmidt 2020 年 3 月 11 日
I just added what I've been trying. I took out the * in the %*s to stop skipping over the 'known' and 'free', but the final output still isn't populating the way I'm trying to get it.

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

採用された回答

the cyclist
the cyclist 2020 年 3 月 11 日
編集済み: the cyclist 2020 年 3 月 11 日
NF_array = [{'1, known, known, 0.0, 0.0'}, ...
{'8, known, known, 0.0, 0.0'}, ...
{'4, free, known, 0.0, 0.0' }, ...
{'5, free, known, 0.0, 0.0' }];
Nodal_Fixity = cell(4,5);
for nr = 1:4
Nodal_Fixity(nr,:) = strsplit(NF_array{nr},',');
end
If you also need to remove the spaces, then follow that with
Nodal_Fixity = regexprep(Nodal_Fixity,' ','');
That does not need to be inside the loop; it will operate on the entire cell array.
  4 件のコメント
Damon Schmidt
Damon Schmidt 2020 年 3 月 11 日
I was able to tweak my loop to account for the result being a cell array. Thanks again for the help.
Stephen23
Stephen23 2020 年 3 月 12 日
編集済み: Stephen23 2020 年 3 月 12 日
Note:
  • importing/storing numeric data as character/string and then converting it to numeric afterwards is going to be less efficient than importing it as numeric in the first place.
  • Storing numeric data as scalar arrays in a cell array is much less efficient than storing it in a simple numeric array.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by