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
2 views (last 30 days)
Show older comments
3 Comments
Answers (1)
Image Analyst
on 14 Dec 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 Comments
Image Analyst
on 14 Dec 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;
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!