How to make a loop through *.asc data

조회 수: 1 (최근 30일)
Ante
Ante 2023년 7월 4일
답변: Aditya Singh 2023년 7월 5일
I am not so skillfull in matlab, and need your help. I found how to read data form the *.asc file, and now, based on these data I should to make loop through thair rows. How can I define that my loop goes from the first up till the late read row from the *.asc data, and how to write this expression in matlab.
You can see the problem below...
clc
clear all
close all
[filename1 pathname1]=uigetfile({'*.asc'},'file selector')
fullpathname1=strcat(pathname1,filename1)
text1=textread(fullpathname1);
%g=texread('Dfree1.txt) % this is the syntax
t=text1(:,1);
w1=text1(:,2);
w2=text1(:,3);
w3=text1(:,4);
wm=text1(:,5);
temp_out=text1(:,6);
temp_spec=text1(:,7);
DMS=text1(:,8);
s=(w2+w3)/2-w1;
for ii=1:N
dW(ii)=0.5*(text1(ii-1,8)-text1(ii,8))*(text1(ii-1,5)+text1(ii,5))
end

답변 (1개)

Aditya Singh
Aditya Singh 2023년 7월 5일
Hi Ante,
To my understanding you want to read a .asc file and iterate through the data. As the asc files contains character strings one can iterate through them and store into a cell array. In the code sample I iterate through the file one line at a time.
out = textread('test.asc','%s', 'delimiter', '\n');
C = cell2mat(out);
That just reads the whole file into a string, reading one line at a time. My test.asc was a sample asc file found Example ASC file - IBM Documentation.
For more information you can refer:
Hope it helps

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by