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)
  3 Comments
Mr Thadi
Mr Thadi on 14 Dec 2023
Moved: Dyuman Joshi on 14 Dec 2023
sure Mr.joshi .i am sharing data for few days in below text file .i am trying for cegrigade different variables with different columns for plot Temperature,Hight for different days in one plot.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 14 Dec 2023
Try this:
fileName = "radio.txt";
data = readmatrix(fileName, 'NumHeaderLines', 5)
data = 4696×11
1.0e+04 * 0.1010 0.0016 0.0025 0.0024 0.0092 0.0019 0 0 0.0298 0.0353 0.0301 0.1007 0.0041 0.0026 0.0024 0.0086 0.0019 0.0308 0.0001 0.0299 0.0353 0.0302 0.1000 0.0100 0.0026 0.0024 0.0085 0.0019 0.0185 0.0002 0.0299 0.0354 0.0303 0.0995 0.0144 0.0026 0.0023 0.0085 0.0019 0.0185 0.0003 0.0300 0.0354 0.0303 0.0979 0.0288 0.0025 0.0023 0.0086 0.0018 0.0190 0.0006 0.0300 0.0353 0.0303 0.0978 0.0297 0.0025 0.0023 0.0086 0.0018 0.0190 0.0006 0.0300 0.0353 0.0303 0.0945 0.0598 0.0023 0.0021 0.0087 0.0017 0.0200 0.0009 0.0301 0.0351 0.0304 0.0925 0.0786 0.0022 0.0020 0.0087 0.0016 0.0230 0.0008 0.0302 0.0349 0.0305 0.0918 0.0852 0.0022 0.0019 0.0087 0.0016 0.0233 0.0008 0.0302 0.0349 0.0305 0.0913 0.0900 0.0022 0.0019 0.0085 0.0015 0.0235 0.0008 0.0302 0.0348 0.0305
% 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
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;

Sign in to comment.

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!