How do i set empty matrix elements to zero?
19 ビュー (過去 30 日間)
古いコメントを表示

How can i set the empty elements in the above picture to zero, i have tried T = cellfun('isempty', Z),
but it does not recognize the cells as empty.
Anyone got ideas of how to do this?
2 件のコメント
Guillaume
2019 年 3 月 11 日
It's impossible for us to know from a screenshot what type of data you have. Assuming it's a cell array, it's also impossible for us to know if the cells are actually empty.
It's much better if you attach your data as a mat file. Screenshots are useless.
KALYAN ACHARJYA
2019 年 3 月 11 日
編集済み: KALYAN ACHARJYA
2019 年 3 月 11 日
Please attach the file, so that we can try on it.
回答 (1 件)
Navdha Agarwal
2019 年 6 月 20 日
Following assumptions are made for the solution stated below:
- The csv file is being read as a matrix and some cells are actually empty.
- The name of the file is 'file1.csv'
- When the file is read as the matrix, the empty cells are automatically recognized as 'NaN'.
The code for the question, keeping the above assumptions is:
A = readmatrix('file1.csv');
dim = size(A);
for i = 1:dim(1)
for j = 1:dim(2)
if isnan(A(i,j))
A(i,j) = 0;
end
end
end
disp(A)
1 件のコメント
Rik
2019 年 6 月 20 日
The loops are not needed, you can simply use the line below:
A(isnan(A))=0;
参考
カテゴリ
Help Center および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!