이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I've created, by concatenating inputs from the user, a path to files on my computer that contain data I want to read into matlab. Example:
pt = input('Enter number:','s')
run = input('Enter run number','s');
task = input('What task?','s');
run_task = strcat(run,'_',task)
pt_plus_run = strcat(pt,'_',run)
main_path='C:\XXXXX\XXXX_ XXXX\XXX_ files',
path_to_data=strcat(main_path,'\',pt,'\',pt_plus_run,'\',pt_run_task)
data=dlmread(path_to_data,',', [1 2 -1 7])
It is at the dlmread statement that the code chhkes. Can I use a concatentated string variable in dlmread?
Thanks for your help!
댓글 수: 1
Fangjun Jiang
2011년 11월 22일
Use {}Code format next time.
채택된 답변
Fangjun Jiang
2011년 11월 22일
0 개 추천
Check the help of dlmread(). I believe the range [R1, C1, R2, C2] won't allow negative number.
use fullfile() instead of strcat() to combine path and file name.
댓글 수: 19
Frank
2011년 11월 22일
Would you elaborate on the {} code you recommended?
Also, the following chokes at the dlmread: Any suggestions?
pt = input('Enter pt number:','s')
run = input('Enter run number:','s');
task = input('What task?','s');
pt_plus_run = strcat(pt,'_',run)
pt_run_task = strcat(pt,'_',run, '_',task,'.csv')
fullfile_name=fullfile('x:','xxxxx','xxxxxxxx','xxxxxxx',pt,pt_plus_run,pt_run_task)
data=dlmread(fullfile_name,[1 2 -1 7])
Fangjun Jiang
2011년 11월 22일
The {}Code is a button above your question box for you to apply formatting.
What do you mean by [1 2 -1 7] in the call of dlmread()?
Frank
2011년 11월 22일
I still don't understand what you mean by {}Code
Regarding [1 2 -1 7] I'm referring to the third ( zeroth being the first) through eigth column from the second row to the bottom of the column
Fangjun Jiang
2011년 11월 22일
I don't see anywhere that the range can be a negative number.
Frank
2011년 11월 22일
Try it. It works for me to read to the bottom of the columns.
Fangjun Jiang
2011년 11월 22일
Okay, thank you! I learned a trick today!
What is the error or problem you are having then? Did you check fullfile_name is correct?
Fangjun Jiang
2011년 11월 22일
You forgot to specify the delimiter in the code in your comment.
Frank
2011년 11월 22일
It chokes at the dlmread comment:
Here is the error message:
??? Error using ==> dlmread at 62
The file 'E:\xxxx\xxxx\xxxx\_\__.csv' could not be
opened because: No such file or directory
Error in ==> Concatenate at 15
data=dlmread(fullfile_name)
Fangjun Jiang
2011년 11월 22일
All right, then check the full path and name of the file. exist(fullfile_name,'file')
Frank
2011년 11월 22일
OK, I'm working through it.
Frank
2011년 11월 22일
Thank you for your direction.
Frank
2011년 11월 23일
OK, so the path doesn't exist what do I do? What is wrong with this script?
pt = input('Enter pt number (001 to 010):','s')
run = input('Enter the run number (R0 to R3):','s');
task = input('What task? ','s');
pt_plus_run = strcat(pt,'_',run)
pt_run_task = strcat(pt,'_',run, '_',task,'.csv')
%main_path='E:\BK\acd_ Study\cd_Study_ CSV_ files'
%path_to_data=strcat(main_path,'\',pt,'\',pt_plus_run,'\',pt_run_task)
fullfile_name=fullfile('E:','BK','acd_Study','cd_Study_CSV_files',pt,pt_plus_run,pt_run_task)
exist('fullfile_name','file')
Fangjun Jiang
2011년 11월 23일
I don't know. Just run your code line by line to see where is the problem. You know your file name convention. You know your folder structure. Just try to match the string with the actual file. I usually use fullfile this way, for example
PathStr='c:\mydocument\mydata';
FileName='mydata.txt';
fullfile(PathStr,FileName);
But nothing is wrong using it like you did.
Frank
2011년 11월 23일
The code "works" until the last time, when exist gives me a zero!
I'll tinker some more. If tomorrow is a holiday for you, enjoy it!
Frank
2011년 11월 29일
Progress has been slooooooooow: Here is what I've got and the resultant errors:
pt = input('Enter pt number (001 to 010):','s');
run = input('Enter the run number (R0 to R3):','s');
task = input('What task? Choose from ar, ae, hb, ct, dr, ds, or am):','s');
upper_or_lower= input ('Upper (enter BD_UE) or lower (enter BE_LE)?','s');
pt_plus_run = strcat(pt,'_',run);
pt_run_task = strcat(pt,'_', task, '_', run, '_', upper_or_lower, '.csv');
whole_sensor_data_file_path= strcat('E:\Bck\aCl_Study\Cl_CSV_files','\', pt,'\', pt_plus_run,'\', pt_run_task)
exist('whole_sensor_data_file_path','file')
PathStr=whole_sensor_data_file_path
FileName=pt_run_task
f= fullfile(PathStr,FileName)
dlmread('f', [1 2 -1 7])
OUTPUT and ERRORS:
ans =
0
PathStr =
E:\Bck\aCl_Study\Cl_CSV_files\001\001_R0\001_ar_R0_BD_UE.csv
FileName =
001_ar_R0_BD_UE.csv
f =
E:\Bck\aCl_Study\Cl_CSV_files\001\001_R0\001_ar_R0_BD_UE.csv\001_ar_R0_BD_UE.csv
??? Error using ==> sprintf
Invalid format.
Error in ==> dlmread at 72
delimiter = sprintf(delimiter); % Interpret \t (if necessary)
Error in ==> test_pad at 15
dlmread('f', [1 2 -1 7])
Any help and/or ideas are appreciated!!!
Fangjun Jiang
2011년 11월 29일
No. f is already a string. use dlmread(f, [1 2 -1 7])
Frank
2011년 11월 29일
??? Error using ==> sprintf
These are the errors I get using dlmread(f, [1 2 -1 7])
Invalid format.
Error in ==> dlmread at 72
delimiter = sprintf(delimiter); % Interpret \t (if necessary)
Error in ==> Concatenate at 18
dlmread(f, [1 2 -1 7])
Frank
2011년 11월 29일
Does anybody have any idea what the heck is wrong with my dlmread--that is where it chokes!!!!!
Walter Roberson
2011년 11월 29일
exist('whole_sensor_data_file_path','file')
should be
exist(whole_sensor_data_file_path,'file')
The whole_sensor_data_file_path you construct includes pt_run_task so it includes .csv at the end. But then you assign whole_sensor_data_file_path to PathStr and you assign pt_run_task to FileName and then you fullfile() together the combination of the two. That is going to add the file name string complete with .csv on to the end of a string that already includes all of that. The name that gets constructed will not be something you can open .
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Text Files에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
