why is uigetfile not reading files the same way as xlsread?
1 view (last 30 days)
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.
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);
(there is more in the forloop but this is not the problem.)
Ingrid on 28 Oct 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
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.