Simple question regarding data files

3 ビュー (過去 30 日間)
Minh Nguyen
Minh Nguyen 2014 年 3 月 4 日
編集済み: Minh Nguyen 2014 年 3 月 4 日
3)For a biomedical experiment, the names and weights of some patients have been stored in a file patwts.dat. For example, the file might look like this: Joe Schmo 110.5 Jane Lang 235.4 Mickey Mouse 150.3 Justin Alabama 650.2 Create this data file first.
Am I suppose make a matrix and save it to a data file? If so, I'm not sure what type of matrix to make it.
  1 件のコメント
per isakson
per isakson 2014 年 3 月 4 日
編集済み: per isakson 2014 年 3 月 4 日
You need a cell array to store both numerical and text.
There is also a data type table, but I doubt you need that.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2014 年 3 月 4 日
編集済み: Image Analyst 2014 年 3 月 4 日
You could use a cell array, but I find an array of structures easier - you never have to figure out if you need parentheses of braces. You can create your text file and then read it in with fgetl() and create your structure
fid = fopen('fgetl.m');
tline = fgetl(fid);
counter = 1;
while ischar(tline)
%disp(tline)
% First line is name.
tline = fgetl(fid);
patientData(counter).name = tline; % Assign field of the structure
% Next line is weight
tline = fgetl(fid);
% Next line is the weight.
patientData(counter).weight= str2double(tline);
% Move on to the next structure.
counter = counter + 1;
end
fclose(fid);
  2 件のコメント
Minh Nguyen
Minh Nguyen 2014 年 3 月 4 日
My question is actually even simpler. How do I make the text file to begin with? I'm stuck on the "Create this data file first"
Minh Nguyen
Minh Nguyen 2014 年 3 月 4 日
編集済み: Minh Nguyen 2014 年 3 月 4 日
I figured it out, thank you, just as simple as making a text file and saving it as .dat

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by