i have ascii data converted into columns and rows seperatby str2num command now i want to add all rows in orderly in one cell by using for loop can you give me ans
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1566519/image.png)
3 Commenti
Risposte (1)
Image Analyst
il 14 Dic 2023
Try this:
fileName = "radio.txt";
data = readmatrix(fileName, 'NumHeaderLines', 5)
% Turn nans into 0's.
data(isnan(data)) = 0;
% Sum up each column over all the rows in that column.
columnSums = sum(data, 1);
bar(columnSums);
grid on;
4 Commenti
Image Analyst
il 14 Dic 2023
@Mr Thadi Why? Why do you want to mess with the complications of cell arrays, fopen, strcmp, etc. when you don't have to??? Why not do it like I said, or with the modification @Voss suggested about tossing out any rows with 1 or more nans in them? Voss's suggestion would be
fileName = "radio.txt";
data = readmatrix(fileName, 'NumHeaderLines', 5)
% Throw out any rows that have a nan in them.
badRows = any(isnan(data), 2);
data = data(~badRows, :);
% Sum up each column over all the rows in that column.
columnSums = sum(data, 1);
bar(columnSums);
grid on;
Vedere anche
Categorie
Scopri di più su Database Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!