error using dlmread (line 62)

1 次查看(过去 30 天)
Hi,
Our teacher gave us a code and he showed us the source data and video tutorial to run the problem. I have just followed the instruction but it shows me below error:
Error using dlmread (line 62)
The file 'bottleneck_caserne/b200_combined.txt' could not be opened because: No such file or directory
In video tutoria teacher shows it work well and I have downloaded the code and txt file which teacher shows but for me I am getting error.
What could be the reason?
Please advise
Thanks
  3 个评论
dpb
dpb 2021-5-1
编辑:dpb 2021-5-1
"I have downloaded the code and txt file..."
As the error message says and DGM questions, the file doesn't exist where the code expects it to be -- you probably just downloaded the file and it is in the current working directory or your default download location; you didn't create a new local folder/subdirectory of the name bottlenec_caserne that is where it is expected to be.
Either create the directory and put the file in it (relative to where you are running the code from as it is still not a fully qualified filename) or change the path to match where you have the file on your system.
MOHAMMAD ABDUL MOKTADIR CHOWDHURY
I have fixed the error. Thanks for the advice.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2021-5-1
编辑:Jan 2021-5-1
The command:
dlmread('bottleneck_caserne/b200_combined.txt');
searchs the folder "bottleneck_caserne" in the current folder. Call e.g. cd to display, what the furrent folder is. I guess, that this folder is a child folder of the M-file. Then specify this explicitly:
myPath = fileparts(mfilename('fullpath'));
dlmread(fullfile(myPath, 'bottleneck_caserne/b200_combined.txt'));
Your teacher gave you a code starting with the brute clearing header:
clc; clear all; close all;
This kind of programming was useful before functions have been introduced in Matlab (more than 5 years ago). removing all functions from the memory by |clear all forces Matlab to reaload them from the slow disk the nect time, they are called. This is a waste of time and energy, but offers no benefit. Tell your teacher, that it is time to stop teaching "Cargo Cult Programming" techniques.
Using absolute instead of the fragile realtive path names would be a good suggestion also.
frame = sort(unique(pedtable.Frame))
The sort is not needed anymore since Matlab R2013a.
  2 个评论
dpb
dpb 2021-5-1
It's unfortunate we see this in so much code, indeed; I rarely download the example code given when it has a clear in it here in forum because I don't want to risk making a slip and accidentally executing it and wiping my working environment while trying to help ... just not worth the risk. I sometimes will either comment out or not include the line(s) in the code formatted segment so it won't get selected automagically by someone else...a little "editor's license"
But, I understand why instructors still do this -- it's a reflection of the structure of MATLAB where (almost) everything is "alias-able" by accident or inexperience and so it sets the same groundwork for homework problems to ensure they don't have to answer the inevitable questions that arise when common functions are inadvertently renamed or the like. We all know the mass confusion this sows with the inexperienced when they do so without realizing what have done...
There's no easy answer, methinks...although we all know it's not good practice in the long run and unfortunately, taught habits tend to run deep.
Jan
Jan 2021-5-1
it's a reflection of the structure of MATLAB where (almost) everything is "alias-able"
I agree with this explanation. I've aliased the clear comnmand to avoid troubles with code taken from the forum or when testing FEX submissions.
Unfortantely the built-in clear command uses magic strings: As soon as e.g. "all" is defined as a variable, the clear command does not work as expected anymore:
str = 'I''m still here';
all = 17;
clear all
disp(str)
% I'm still here
This concerns the string "all", "classes", "functions", "import", "mex", "java" and "variables". There is no legal way to call a variable "global". Modern extensions like "-regexp" are escaped by the "-" to avoid increasing the set of magic strings, but the method remains flawe - and must be kept fpr backward compatibility.
See this puzzle, where a shadowed clear makes it hard to clear.
Although a clear all helps to remove formerly shadowed functions, like in:
sum = 1 + 2;
...
sum(1:10) % Failing
But you find exactly this problem in many questions in the forum, when the function was shadowed after the clear all.
An easy solution is using functions instead of scripts. The need to clear shadowed functions or to remove orphaned arrays vanishes automatically.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by