I have a text file example (data AAA txt.) that is a string of numbers. There ar
ID: 3622709 • Letter: I
Question
I have a text file example (data AAA txt.) that is a string of numbers. There are no commas, or anything to separate them. They are on notepad and when the file is opened they take the form below. I need the syntax and procedure to import them or the file into matlab. I'm new at this so step by step would be good. Do I do it in the editor window or the command line?131
201
75
103
128
148
190
131
126
171
131
188
130
135
133
96
75
73
192
97
188
166
189
199
83
120
205
156
193
133
65
153
96
139
168
151
148
126
98
125
64
151
202
77
68
191
99
64
181
83
190
77
114
149
148
160
157
126
83
172
98
157
187
75
204
67
184
184
70
142
200
109
180
150
177
179
70
104
158
134
204
171
145
106
100
191
128
181
77
187
67
193
193
139
80
89
165
183
68
173
202
113
155
113
94
177
168
103
147
124
76
66
134
103
112
104
88
121
164
92
159
127
126
88
91
152
102
144
200
166
161
202
175
151
200
71
102
206
175
132
162
123
118
94
118
67
131
111
204
143
186
122
130
183
207
139
197
170
145
203
182
202
157
118
132
195
65
86
131
142
71
158
192
79
126
103
206
151
100
82
142
183
184
184
92
142
190
80
187
193
94
74
132
184
131
123
136
81
82
189
150
101
188
71
129
168
112
121
139
192
176
73
103
118
188
124
98
149
132
193
198
181
166
171
193
72
112
63
183
136
116
96
140
105
73
75
73
122
81
127
193
114
80
145
190
113
69
83
74
170
129
160
164
146
154
190
159
190
131
83
73
166
107
160
157
140
167
136
134
135
199
119
80
98
Explanation / Answer
%First, you have to find the text file. Remember the path where you put %it, and then simply change the path to where the text file is.
cd c:examplePath
% Now you can use fopen to open the file
fileID = fopen('yourTextFile.txt');
% the fileID is what Matlab uses to address this file. Fopen also tags the file as 'in use', so you will not be able to delete it at the moment.
% read the content of the file with fseek, which takes three inputs: the fileID, the number of entries to read and the format. You have obtained the fileID already. You want to read everything, so you say fseek should read an infinite amount of characters (or however many there are), and format-wise, you want to convert from characters to integers.
In Matlab, you write this as such:
v = fread(fileID,inf,'char=>int');
% fread returns the transpose of the vector you're supposed to get, so if the teacher is picky, transpose v. Now do not forget to close the file, so that some other program can have its way with it.
fclose(fileID)
SHORT CUT:
a = load(a.txt) % assuming a.txt is your file with those numbers
then
a is nothing but a column matrix with that many rows as text file and single column
now access matrix a as u want
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.