readlines function returns an empty string array

I have a file with the extension "dataset", that follows the template shown below. When I have the following code:
lines = readlines("myfile.dataset","EmptyLineRule","skip")
I get an output of:
lines =
0×1 empty string array
Any ideas?
Template for dataset:
<Database Name>
<Image X Axis/Width> <Image Y Axis/Height>
<Count>
+1 <Path to Image 1>
+1 <Path to Image 2...>

4 件のコメント

Image Analyst
Image Analyst 2022 年 11 月 12 日
No, because you forgot to attach the actual file with the paperclip icon.
If you have any more questions, then attach "myfile.dataset" with the paperclip icon after you read this:
Liam
Liam 2022 年 11 月 12 日
I've had to attach this as a .txt file as a result of the upload validation (.dataset prohibited)
Karim
Karim 2022 年 11 月 12 日
Hmm evrything seems to work? You can try to zip the original file and upload the zip.
% read in the text file provided by the OP
lines = readlines("https://nl.mathworks.com/matlabcentral/answers/uploaded_files/1190428/face_train.txt","EmptyLineRule","skip");
% write the text into a .database file
writelines(lines,"myfile.dataset")
% now try to read the .dataset file
lines = readlines("myfile.dataset","EmptyLineRule","skip")
lines = 13×1 string array
"MyDataset" "20 30" "10" "+1 images/face/1.jpg" "+1 images/face/2.jpg" "+1 images/face/3.jpg" "+1 images/face/4.jpg" "+1 images/face/5.jpg" "+1 images/face/6.jpg" "+1 images/face/7.jpg" "+1 images/face/8.jpg" "+1 images/face/9.jpg" "+1 images/face/10.jpg"
Liam
Liam 2022 年 11 月 12 日
I'm such a muppet.. Took me ages to realise I was referencing the wrong version (an empty version).. Sorry guys
Thanks for your help tho!

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

回答 (1 件)

Jan
Jan 2022 年 11 月 12 日
編集済み: Jan 2022 年 11 月 12 日

0 投票

My first idea concerns the relative path:
lines = readlines("myfile.dataset", "EmptyLineRule", "skip")
Is the current folder really what you expect it to be? Check this:
D = dir(fullfile(cd, "myfile.dataset"))
Is this file empty? If so, specify the correct path instead:
folder = "C:\Your\Folder";
file = fullfile(folder, "myfile.dataset");
lines = readlines(file, "EmptyLineRule", "skip")

カテゴリ

製品

リリース

R2022b

質問済み:

2022 年 11 月 12 日

編集済み:

Jan
2022 年 11 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by