why is uigetfile not reading files the same way as xlsread?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a CSV file which reads in fine and produces the desired output when I use "xlsread" however, I require my programme to use a user interface so alternate files can be selected, so I tried "uigetfile" however when my for loop tries to use this it returns "Attempted to access b(2,1); index out of bounds because size(b)=[1,20]" Below is roughly the code causing the problem.
k=uigetfile('.csv')
for j=1:31
val_1 = b(j,1);
val_2 = b(j,2);
val_3 = b(j,3);
val_4 = b(j,4);
val_5 = b(j,5);
val_6 = b(j,6);
val_7 = b(j,7);
val_8 = b(j,8);
val_9 = b(j,9);
val_10= b(j,10);
val_11= b(j,11);
val_13= b(j,13);
val_12= b(j,12);
end
(there is more in the forloop but this is not the problem.)
0 Commenti
Risposte (1)
Ingrid
il 28 Ott 2015
did you even read the documentation on uitgetfile? It does not return the data inside the file, it just returns the name of the file the user selected. You have to use this name with an fopen statement to get an fid (file identifier - do not forget to close with fclose) and then use textscan or whatever you prefer to actually read in the data that you want.
below the documentation provided by matlab after typing
doc uitgetfile
filename = uigetfile displays a modal dialog box that lists files in the current folder and enables you to select or enter the name of a file. If the file name is valid and the file exists, uigetfile returns the file name as a string when you click Open. Otherwise uigetfile displays an appropriate error message, after which control returns to the dialog box. You can then enter another file name or click Cancel. If you click Cancel or close the dialog window, uigetfile returns 0.
0 Commenti
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!