Hey guys, i need help inserting a cell array into a cell in another cell array. My problem has the form of this:
%INPUT
A = {'one''two''three'};
B = {'four''five''six'};
B{1,1} = A{1,:}
%WANTED OUTPUT
B = {'one''two''three'},{'five'},{'six'}
I really hope someone can help

 Akzeptierte Antwort

VBBV
VBBV am 11 Nov. 2022

1 Stimme

%INPUT
A = {'one''two''three'};
B = {A,'four''five''six'};

7 Kommentare

%INPUT
A = {'one''two''three'};
B = {{'four'},{'five'},{'six'}}
B = 1×3 cell array
{1×1 cell} {1×1 cell} {1×1 cell}
B = {A,B} % do you mean this ?
B = 1×2 cell array
{1×1 cell} {1×3 cell}
The thing is i want A, B to change in a loop, so i want them to be like this.
D = 1
C = num2str(D)
A = {'one'C 'three'};
B = {'one''two''three'};
C = num2str()
For i in range n
print(B)
D = D+1
C = num2str(D)
A = {'one'C 'three'};
B{1,1} = A
B = [B,A]
%Output
B = {'one'}{'two'}{'three'}
B = {'one'}{C}{'three'}{'one'}{C}{'three'}
B = {'one'}{C}{'three'}{'one'}{C}{'three'}{'one'}{C}{'three'}
.
.
B = {'one'}{C}{'three'} {'one'}{C}{'three'} {'one'}{C}{'three'} ....
D = 1;
C = num2str(D);
A = {'one',C, 'three'};
B = {{'one'},{'two'},{'three'}};
B{1,1} = A ;
n = 10;
for i = 1:n
D = D+1;
C = num2str(D);
A = {{'one'},{C}, {'three'}};
B{i} = {B,A}
end
B = 1×3 cell array
{1×2 cell} {1×1 cell} {1×1 cell}
B = 1×3 cell array
{1×2 cell} {1×2 cell} {1×1 cell}
B = 1×3 cell array
{1×2 cell} {1×2 cell} {1×2 cell}
B = 1×4 cell array
{1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell}
B = 1×5 cell array
{1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell}
B = 1×6 cell array
{1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell}
B = 1×7 cell array
{1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell}
B = 1×8 cell array
{1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell}
B = 1×9 cell array
{1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell}
B = 1×10 cell array
{1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell} {1×2 cell}
Tobias Egebjerg
Tobias Egebjerg am 11 Nov. 2022
It seems like all the strings are lost, is that right ?
Stephen23
Stephen23 am 11 Nov. 2022
"It seems like all the strings are lost, is that right ? "
I doubt that. How did you check that the strings are "lost" ?
Tobias Egebjerg
Tobias Egebjerg am 11 Nov. 2022
@Stephen23 I ran the script and it only creates empty cell arrays.
D = 1;
C = num2str(D);
A = {'one',C, 'three'};
B = {{'one'},{'two'},{'three'}};
B{1,1} = A ;
n = 10;
for i = 1:n
D = D+1;
C = num2str(D);
A = {{'one'},{C}, {'three'}};
B{i} = {B,A};
end
B{:}
ans = 1×2 cell array
{1×3 cell} {1×3 cell}
ans = 1×2 cell array
{1×3 cell} {1×3 cell}
ans = 1×2 cell array
{1×3 cell} {1×3 cell}
ans = 1×2 cell array
{1×3 cell} {1×3 cell}
ans = 1×2 cell array
{1×4 cell} {1×3 cell}
ans = 1×2 cell array
{1×5 cell} {1×3 cell}
ans = 1×2 cell array
{1×6 cell} {1×3 cell}
ans = 1×2 cell array
{1×7 cell} {1×3 cell}
ans = 1×2 cell array
{1×8 cell} {1×3 cell}
ans = 1×2 cell array
{1×9 cell} {1×3 cell}
B{1}
ans = 1×2 cell array
{1×3 cell} {1×3 cell}
B{1}{1}{:}
ans = 1×3 cell array
{'one'} {'1'} {'three'}
ans = 1×1 cell array
{'two'}
ans = 1×1 cell array
{'three'}
B{1}{2}{:}
ans = 1×1 cell array
{'one'}
ans = 1×1 cell array
{'2'}
ans = 1×1 cell array
{'three'}
What exactly do you mean by "lost" ?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by