Remove the 1x1 Cell Array from the Cell Array

12 ビュー (過去 30 日間)
Ahmed Radhi
Ahmed Radhi 2022 年 9 月 27 日
コメント済み: Ahmed Radhi 2022 年 9 月 27 日
Hey everyone,
I have the following code:
s{1} = [4 2];
s{2} = [2 1];
S{1} = [s{1}];
m = 1;
m = 1
for j = 1:m
Temp_D{j} = S{j} - s{j+1};
end
Temp_D = cell2sym(Temp_D);
D{1} = Temp_D;
D{1}
ans = 
However, when I use this chunk of code as a function in my code, I get the following result :
Why do I need to do D{1}{1} To access the the array [2, 1], can I solve this problem?
  2 件のコメント
Jan
Jan 2022 年 9 月 27 日
Why do you consider this as a "problem". It is exactly, what the code instructs Matlab to do. What do you want instead?
Ahmed Radhi
Ahmed Radhi 2022 年 9 月 27 日
Because I want the output to be D{1} = [2, 1], instead.
In this way, let’s assume I added one more array to D, such that D{2} = [1, 2, 0], how can I access it? Is it by D{2}{1}?

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

採用された回答

Jan
Jan 2022 年 9 月 27 日
編集済み: Jan 2022 年 9 月 27 日
If you want D{1} = [2, 1], use:
D{1} = [2, 1]
D = 1×1 cell array
{[2 1]}
% or equivalently
D = {[2, 1]}
D = 1×1 cell array
{[2 1]}
Expanded:
D = {[2,1], [1,2,0]}
D = 1×2 cell array
{[2 1]} {[1 2 0]}
D{1}
ans = 1×2
2 1
D{2}
ans = 1×3
1 2 0
Maybe in your case:
D = Temp_D;
% not D{1} = ...
What is the purpose of cell2sym?
  3 件のコメント
Jan
Jan 2022 年 9 月 27 日
Okay. Do you really want a symbolic array?
Ahmed Radhi
Ahmed Radhi 2022 年 9 月 27 日
I used the cell2sym to put all the arrays in Temp_D in one array, and then I can put it as a single array in the first cell of D. So yes I want a symbolic array.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by