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

1 次查看(过去 30 天)
  3 个评论
Mr Thadi
Mr Thadi 2023-12-14
移动:Dyuman Joshi 2023-12-14
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.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2023-12-14
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 个评论
Image Analyst
Image Analyst 2023-12-14
@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;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by