Good morning everyone. New day and one more Question too. It is about again read from text files. I take datas from device as a text file. In first Picture you see that i defined Parameters as a structure which are in s Matrix. The next step that i should do is: under these Parameters there are too many value that each column belong to one Parameter. First question how can i read values from text file (be careful there are semicoluns too)and than after i read how can i connect this numbers with Parameters.
<<
>>

댓글 수: 4

cemsi888
cemsi888 2015년 1월 27일
편집: cemsi888 2015년 1월 27일
clear all
clc
delimiter=';' ; headerLines=4
formatSpec = '%s%s%s%s%s%s%s%d' daten=fopen('msa02_141121_mscc5_11.erg','r') %textread ('/Users/test.txt','%s', 'delimiter', '\n'); % zeile=textscan(datei,'%s\t',[1,inf]) zeile = textscan(daten,formatSpec,181,'delimiter',';','headerLines',4) fclose(daten);
for i=1:length(zeile{1,1}) tmp=zeile{1,1}{i} tmp=strrep(tmp,'.','_dot') zeile{1,1}(i)=cellstr(tmp); end
for ind=1:size(zeile{1,1},1)
%s.(zeile(i){ind})=magic(length(zeile{ind}))
s.(zeile{1,1}{ind})=magic(size(zeile{1,1}{ind},1))
end
cemsi888
cemsi888 2015년 1월 27일
cemsi888
cemsi888 2015년 1월 27일
and the values start from 230.th row
Stephen23
Stephen23 2015년 1월 27일
You use the format specifier '%s' to read numeric data: why not just convert this immediately to numeric using the '%f' specifier, as all of your data seems to be floating point values.

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

 채택된 답변

Stephen23
Stephen23 2015년 1월 27일
편집: Stephen23 2015년 1월 27일

0 개 추천

Do not do this. Dynamically assigning variable names is a really bad idea in MATLAB:
The best alternatives are to keep your data in an array (e.g. as they are returned from your file-reading function), or if you require key-value access to your data then use a structure . Structures do allow dynamic fieldnames , and this is much more robust than dynamic variables.
If you have a newer version of matlab you can also use a table , which stores the data together in one array but also allows key-name access to the columns.
Summary: use a structure or table to store your data.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Text Data Preparation에 대해 자세히 알아보기

질문:

2015년 1월 27일

댓글:

2015년 1월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by