Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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]

Risposta accettata

the cyclist
the cyclist il 11 Mar 2020
Modificato: the cyclist il 11 Mar 2020
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 Commenti
Damon Schmidt
Damon Schmidt il 11 Mar 2020
I was able to tweak my loop to account for the result being a cell array. Thanks again for the help.
Stephen23
Stephen23 il 12 Mar 2020
Modificato: Stephen23 il 12 Mar 2020
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.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by