필터 지우기
필터 지우기

values in file names

조회 수: 2 (최근 30일)
franco otaola
franco otaola 2016년 10월 10일
댓글: franco otaola 2016년 10월 10일
hello everybody i am trying to use the name of the files (that are numbers) 09.xls,08.xls....etc. to create a matrix with them so i can relate them with the values they have inside.
d=dir('*.xls')
Name=ones(1,length(d));
for i=1:length(d)
[path,name,ext]=fileparts(d(i).name);
B=Name*name
...
end
my problem is that when i try to use name (as an escalar)to have the value it use '09' for exaple. then i try to make the matrix with all the values together(B) so, each value is stocked inside the matrix as the loop advance, matlab gives me things that doent have any sense (or at least for me...). eg. i have 9 excels, 02,03,04,05,06,07,08,09,10.xls so each time name would give 02,03,04,05,06,07,08,09 and 10 and the matrix Name would be [1;1;1;1;1;1;1;1;1] (a matrix of 9x1) when i try to calculate B (as in the code B=Name*name), matlab gives me B=[48,49;48,49;48,49;48,49;48,49;48,49;48,49;48,49;48,49] (a matrix of 9x2) i typed in the command window Name and name and it gives me the values i attend
>> name
name =
10
>> Name
Name =
1
1
1
1
1
1
1
1
1
>> Name*name
ans =
49 48
49 48
49 48
49 48
49 48
49 48
49 48
49 48
49 48
  댓글 수: 1
franco otaola
franco otaola 2016년 10월 10일
i solved by adding str2num(name) i dont know what it was doing before....

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2016년 10월 10일
d=dir('*.xls')
Name=ones(1,length(d));
for i=1:length(d)
[path,name,ext]=fileparts(d(i).name);
B=Name*name ;
end
In the above Name is number and class double, where as name is string and class char. You cannot multiply two different classes. You have to convert name to number using str2num(). That's why it worked after converting.
You can check the classes of variables using class().
  댓글 수: 1
franco otaola
franco otaola 2016년 10월 10일
Thanks!!!!! the getting started needs to add more things :p

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by