필터 지우기
필터 지우기

How do I read a specific string and numerical value from a .txt file and use each one for calculation?

조회 수: 1 (최근 30일)
So I have .txt file that has the following information:
NameA 1999 50
NameB 2005 75
NameC 1987 86
...
The name, the year, and the number are separated by a tab I am supposed to write a script that would read the above information into MatLAB, use the number in the 3rd column for some calculation, and then display the name, year, and the calculated value in 3 columns onto the command window.
How do I even target the numbers in the 3rd columns?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 24일
im=importdata('file.txt')
num=im.data
c2=num(:,1) % second column
c3=num(:,2) % third column
texte=im.textdata % first column
  댓글 수: 2
John
John 2014년 2월 24일
I'm at the part where I have to print some information with the following format:
fprintf('company %s founded in %d has an income of %f, NameA, Year, Income)
I used the sscanf to break down the 2nd and 3rd column so that I could target each individual year and each individual income.
However, for the 1st column, I couldn't use sscanf to break it downn into single elements since it is composed of String.
How do I do that?
Image Analyst
Image Analyst 2014년 2월 24일
I'm not sure of the problem. It's a string and you want a string and you put %s in the sscanf() statement for it, so what's going wrong? Show you sscanf() statement, because it sounds fine to me.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Predictive Maintenance Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by