Converting cell array containing char to array.

Hi,
I have a few cell arrays that contain char arrays that I need to convert to a single array. Currently the contents of the cell arrays are either numbers or [] for empty cells.
I tried cell2mat, str2num, str2double and all didn't work.
I attached one of the cell arrays.
Any help would be greatly appreciated.
Thanks

2 件のコメント

Fangjun Jiang
Fangjun Jiang 2019 年 2 月 21 日
How do you want to convert "chars" to single array? You can make up a simple cell array to show your problem.
Mohamed Abdelsamie
Mohamed Abdelsamie 2019 年 2 月 21 日
Hi Fangjun,
I'm not sure I understand what you mean. I attached the cell array that I have trouble with.

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

その他の回答 (1 件)

Mohamed Abdelsamie
Mohamed Abdelsamie 2019 年 2 月 21 日
編集済み: Mohamed Abdelsamie 2019 年 2 月 21 日

0 投票

Ok I was able to solve the problem this way:
desired_array=[cell_array{1,1}; cell_array{1,2}; cell_array{1,3};...
cell_array{1,4}; cell_array{1,5}; cell_array{1,6};...
cell_array{1,7}; cell_array{1,8};];
It is still a non numeric array, but all values are in the same single array now not a cell array inside a cell array.
I will leave the question and answer in case it's useful to someone or in case someone has a better solution.

4 件のコメント

Stephen23
Stephen23 2019 年 2 月 21 日
編集済み: Stephen23 2019 年 2 月 21 日
Mohamed Abdelsamie
Mohamed Abdelsamie 2019 年 2 月 21 日
Hi Stephen,
Vertcat didn't change the cell array at all. I will read the links you attached in case there's something to change in the function.
Stephen23
Stephen23 2019 年 2 月 21 日
編集済み: Stephen23 2019 年 2 月 21 日
"Vertcat didn't change the cell array at all"
I would not expect vertcat to "change" anything. All it does is vertically concatenate its inputs together. Which is exactly what you showed in your answer... vertcat with a comma-separated list is just simpler than what you wrote:
desired_array = vertcat(cell_array{1,1:8})
Mohamed Abdelsamie
Mohamed Abdelsamie 2019 年 2 月 21 日
Ok, I see what you mean now. For some reason it didn't work within my main script when I tested it. But it works now.
Could you add your comment as an answer so I could flag it?

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

カテゴリ

製品

リリース

R2018a

質問済み:

2019 年 2 月 21 日

回答済み:

2019 年 2 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by