[A B]=size(SA);
for k=2:A
for j=1:B
if SA(k,j)~=0
as=as+1;
Atable{k,:}(:,as)=[SA(1,j) SA(k,j) SA(k,j)/(e-b+1) log10(SA(k,j)/(e-b+1))];
end
end
end
I have a 1X36 SA matrix and I obtained the values which are not equal to zero but there is an extra empty cell in Atable. How should I modify this code to remove the empty cell?
Also, In the double matrixes, there are some dublicated elements in each row but I want to remove them by keeping the last dublicated value. For example, If I have A matrix, I want to obtain the final A as shown in below.
A=[1 2 3 4 5 6 7 8;0.7 0.7 0.6 0.6 0.6 0.5 0.5 0.4]
Final_A=[2 5 7 8;0.7 0.6 0.5 0.4]

 採用された回答

KSSV
KSSV 2022 年 5 月 30 日

0 投票

Let A be your cell array.
A = A(~cellfun('isempty',A)) ; % A has no more empty cells

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 5 月 30 日

1 投票

format long g
A = [1 2 3 4 5 6 7 8;0.7 0.7 0.6 0.6 0.6 0.5 0.5 0.4]
A = 2×8
1 2 3 4 5 6 7 8 0.7 0.7 0.6 0.6 0.6 0.5 0.5 0.4
[~, ia] = unique(fliplr(A(2,:)), 'stable');
fliplr(A(:,end-ia+1))
ans = 2×4
2 5 7 8 0.7 0.6 0.5 0.4

1 件のコメント

busra gogen
busra gogen 2022 年 5 月 30 日
thank you! It works perfectly..

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

カテゴリ

ヘルプ センター および File ExchangeAgriculture についてさらに検索

質問済み:

2022 年 5 月 30 日

コメント済み:

2022 年 5 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by