필터 지우기
필터 지우기

Reading and writing a 2-column table of strings to text file

조회 수: 8 (최근 30일)
Peter de Goot
Peter de Goot 2020년 6월 4일
댓글: Peter de Goot 2020년 6월 4일
I have a novice question on saving to and loading from text files. I'm new to Matlab, so I need very simple step-by-step instructions on how to do this. Perhaps it is in a tutorial somewhere, that would be fine if someone could point me to it.
I want to save and load values as a text file with two columns. There is a mix of strings and numbers, so everything could be converted to strings before saving. That would be fine.
The first column is a list of parameter names, the second is the value of these parameters.
For example , the first column with three rows might be "parameter name 1", "parameter name 2", "parameter name 3". The second column of three rows might be "100", "200", "Off".
I would like to create this text file, and be able to load and interpret it again. Thank you!

채택된 답변

Takumi
Takumi 2020년 6월 4일
편집: Takumi 2020년 6월 4일
You can find many ways by following the links below.
  댓글 수: 4
Takumi
Takumi 2020년 6월 4일
I made a sample program. Is it helpful?
names = {'param1','param2','param3'};
values = [100,200,NaN];
fname = 'test.txt';
output = [names',num2cell(values)'];
writecell(output,fname)
clear
data = readcell('test.txt');
Names = data(:,1);
Values = cell2mat(data(:,2));
Peter de Goot
Peter de Goot 2020년 6월 4일
Thank you, yes, this is within a program using app designer. The example is very clear, thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by