Hi! How can I merge these two cells?
Final results:

댓글 수: 3

Dyuman Joshi
Dyuman Joshi 2023년 9월 8일
편집: Dyuman Joshi 2023년 9월 8일
@Alberto Acri, just a note - Posting screenshots of code or data is not helpful.
You should attach the code or data with the question.
Also, mentioning the final output is helpful as well. Make it easy for us to help you solve your problem.
With the given info, the obvious "merging" to me is to convert value1 to a 1x1 cell and vertically concate with value2.
Alberto Acri
Alberto Acri 2023년 9월 8일
Hi @Dyuman Joshi! I've updated my question with file and final result!
Stephen23
Stephen23 2023년 9월 8일
@Alberto Acri: note that storing scalar strings in cell arrays is very inefficient, and it avoids all of the benefits of using string arrays. You should be using string arrays, just as the documentation recommends:

댓글을 달려면 로그인하십시오.

 채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 9월 8일

0 개 추천

As you want the final result to be a 4x1 cell array -
mat1 = load('value1.mat');
value1 = mat1.value1;
mat2 = load('value2.mat');
value2 = mat2.value2;
out1 = vertcat({value1},value2)
out1 = 4×1 cell array
{1×6 cell} {1×6 cell} {1×6 cell} {1×6 cell}
In case you want to store them as 4x6 as well -
out2 = vertcat(value1,vertcat(value2{:}))
out2 = 4×6 cell array
{["54"]} {["55"]} {["56"]} {["57"]} {["58"]} {["59"]} {["60"]} {["61"]} {["62"]} {["63"]} {["64"]} {["65"]} {["66"]} {["67"]} {["68"]} {["69"]} {["70"]} {["71"]} {["72"]} {["73"]} {["74"]} {["75"]} {["76"]} {["77"]}

댓글 수: 3

Thanks for the help @Dyuman Joshi. I will use 'out1'. May I ask you how to automatically extract and rename the cell contained in 'out1' with the name 'variable_1', 'variable_2',....?
For example, doing it manually, I would like to obtain this:
mat1 = load('value1.mat');
value1 = mat1.value1;
mat2 = load('value2.mat');
value2 = mat2.value2;
out1 = vertcat({value1},value2)
variable_1 = out1{1,1};
variable_2 = out1{2,1};
variable_3 = out1{3,1};
variable_4 = out1{4,1};
Dynamically naming variables is not recommended - Why Variables Should Not Be Named Dynamically.
Store the data in an array and use indexing to access the data -
mat1 = load('value1.mat');
value1 = mat1.value1;
mat2 = load('value2.mat');
value2 = mat2.value2;
out1 = vertcat({value1},value2)
out1 = 4×1 cell array
{1×6 cell} {1×6 cell} {1×6 cell} {1×6 cell}
variable = vertcat(out1{:})
variable = 4×6 cell array
{["54"]} {["55"]} {["56"]} {["57"]} {["58"]} {["59"]} {["60"]} {["61"]} {["62"]} {["63"]} {["64"]} {["65"]} {["66"]} {["67"]} {["68"]} {["69"]} {["70"]} {["71"]} {["72"]} {["73"]} {["74"]} {["75"]} {["76"]} {["77"]}
Here, variable_k will correspond to the kth row of variable.
Alberto Acri
Alberto Acri 2023년 9월 9일
ok!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품

릴리스

R2021b

질문:

2023년 9월 8일

댓글:

2023년 9월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by