Azzera filtri
Azzera filtri

Get index value of given input

1 visualizzazione (ultimi 30 giorni)
Hi,
I need the index value of a given input.
I have a .xlsx file with in column1 values like 0000150 and M040.
I open the xlsx file and want to find the indexnumber of the variable of 'num' .
Now I have tried the folowing but ofcourse, this doesnt work:
close all; clear all; clc;
% read folder and files
files = dir('C:\Users\dit\Documents\MATLAB\RawData');
dirFlags = [files.isdir];
subFolders = files(dirFlags);
data = readtable('data_gegevens.xlsx');
data2 = table2cell(data(:,1));
for j = 3:length(subFolders)
num = subFolders(j).name;
num2 = convertCharsToStrings(num);
Index = strfind(data2, num2)
end
  2 Commenti
Walter Roberson
Walter Roberson il 17 Feb 2021
I need to open the xlsx file and find the indexnumber of the variable.
I do not understand what you are asking for.
Are you asking to go through the list of subfolders in a given folder, and locate the name in column 1 of the xlsx file, extracting the index for each subfolder name?
If so, that is certainly possible, but you should also define the behaviour you want when the name is not found in the file.
Dion Theunissen
Dion Theunissen il 17 Feb 2021
That is indeed what i want. Now it doesn't find anything

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 17 Feb 2021
Modificato: Walter Roberson il 17 Feb 2021
Note: the comparison that is done will include any file extension that might show up for the subfolders. MS Windows typically hides the file extension for folder names, but there are cases where an extension can be present.
files = dir('C:\Users\dit\Documents\MATLAB\RawData');
dirFlags = [files.isdir];
subFolders = files(dirFlags);
subnames = {subFolders.name};
data = readtable('data_gegevens.xlsx');
col1 = data{:,1};
[found, Index] = ismember(subnames, col1);
if any(~found)
warning('%d subfolders not in list. Their Index will be 0', nnz(~found));
end

Più risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by