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
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.
답변 (1개)
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
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
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.
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 Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!