read table without having reading the directory path

74 visualizaciones (últimos 30 días)
Khairul nur
Khairul nur el 23 de Mzo. de 2021
Respondida: David Ash el 5 de En. de 2023
hi all, this is a simple question and may seems silly.
Currently my table read used syntax :
data_table = readtable('C:\Users\blabla')
However, if i runat different laptop/pc i need to configure the path again.
Please help to suggest and simple code how to solve this. TQ

Respuestas (2)

Mohammad Sami
Mohammad Sami el 23 de Mzo. de 2021
You can have the user select the file to process using the function uigetfile
[file,path] = uigetfile();
if isequal(file,0)
disp('User selected Cancel');
data_table = [];
else
data_table = readtable(fullfile(path,file));
end

David Ash
David Ash el 5 de En. de 2023
You can just change the current folder in the ui as per the attached image, no need to set current folder in the code.

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by