필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by