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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
3 comentarios
Respuestas (1)
Image Analyst
el 14 de Dic. de 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 comentarios
Image Analyst
el 14 de Dic. de 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;
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!