Manipulating Data in cell array, especially Inf

2 ビュー (過去 30 日間)
Oliver-Maximilian Klein
Oliver-Maximilian Klein 2022 年 3 月 19 日
編集済み: Stephen23 2022 年 3 月 19 日
Hey there,
i have a 25x25 cell arrays which includes mostly numbers or doubles to be precise. Now some values are Infinity, displayed by the Inf keyword. Now i want to copy the cell array in to an 2d array and exchange the Inf's with ones. But i cant seem to figure it out. Maybe you guys know more ? With L_d_0 being the 2d cell array containing the data i want to copy / exchange with ones if they are Inf.
L_d_Matrix=zeros(25,25);
for i=1:length(L_d_0)
for j=1:length(L_d_0)
L_d_Matrix(i,j)=L_d_0{i,j};
if L_d_Matrix(i,j) == inf
L_d_Matrix(i,j) = 1;
end
end
end
  2 件のコメント
Oliver-Maximilian Klein
Oliver-Maximilian Klein 2022 年 3 月 19 日
Haha! I shouldve checked my spelling, its because inf is supposed to bei Inf. Yikes ! NVM guys. :)
Stephen23
Stephen23 2022 年 3 月 19 日
編集済み: Stephen23 2022 年 3 月 19 日
isequal(inf,Inf)
ans = logical
1
PS: use ISINF rather than EQ.

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

回答 (1 件)

Burhan Burak AKMAN
Burhan Burak AKMAN 2022 年 3 月 19 日
I think that you can try this method on the other hand, that method shorter than if else method.
%Example Matrix
L_d_Matrix=[inf,5,2;inf,inf,inf;1,2,3]
L_d_Matrix = 3×3
Inf 5 2 Inf Inf Inf 1 2 3
%Here we change inf by one
L_d_Matrix(L_d_Matrix==inf)=1
L_d_Matrix = 3×3
1 5 2 1 1 1 1 2 3

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by