Hello I have been trying to display the dimensions of a dataset, below is the following matlab code that i used...but it gives me the wrong output....i'e number of rows and columns values are wrong....any help regarding this issue would be highly appreciated
[file_input,pathname] = uigetfile( ...
{'*.txt', 'Text (*.txt)'; ...
'*.xls', 'Excel (*.xls)'; ...
'*.*', 'All Files (*.*)'}, ...
'Select files');
uiimport(file_input)
[pathstr, name, ext, versn] = fileparts(file_input)
r = size(name,1);
c = size(name,2);
disp(r)
disp(c)
In this case
name
is the name of the file, which will be a character array. Sor
will always be 1, andc
will be the number of characters in the filename.EDIT: You probably meant to call
readxls
(or similar) on the file identified byfile_input
.I'll comment your code so that you can see what is happening where.
Also, I suggest adding (for debugging purposes) two more disps as indicated so you'll see what is going on.
If you want the size of your dataset, you need to load the dataset first.
Alternatively, if your dataset has always a fixed number of columns, for example, you can try to estimate the number of rows from the size of the file
Firstly, you need to combine
file_input
andpathname
together to create the full path to the file you want. You can do this with the function FULLFILE:Secondly, when you use UIIMPORT you can choose the name for the variable that you want the file data to be loaded into. By default, the variable name is the name of the file you loaded if your file contains only one kind of data (i.e. numbers with no header text), so the following should work if you don't change the name of the variable storing the file data:
You could also do this using the option to output the data from UIIMPORT as a structure where the data is stored in a field (with the file name as the default field name):
If you needed to pass the loaded data to another function, or use it in any other way, you can do the following: