How can I search through a row in a cell array to find strings?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have imported data as a cell array from excel via the xlsread function.
I have searched through the first column in the array using
for i= find(strcmp('string',filename)). This gives me the correct rows that I need to look through to find strings.
How do I search through these found rows to find strings? The array is full of empty spaces and strings. I do not need a specific string, I need any string within that row.
Thank you
2 Kommentare
sixwwwwww
am 4 Dez. 2013
can you show your complete code and your data to ans the question in a better way
Antworten (2)
Walter Roberson
am 4 Dez. 2013
find( ~cellfun( @isempty, YourArray(i, :) ) )
or if you just care whether there is anything non-empty
~all( cellfun( @isempty, YourArray(i,:) ) )
1 Kommentar
sixwwwwww
am 5 Dez. 2013
Bearbeitet: sixwwwwww
am 9 Dez. 2013
Dear Justin, you can find the occurances of string 'DIRs' in cell array as follow:
[~, ~, MyDATA] = xlsread('filename.xlsx','Data Correlation');
MyDATA(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),MyDATA)) = {''};
str = 'DIRs';
StringFoundAt(1, :) = {'Row number', 'Starting index'};
count = 2;
for i = 1:size(MyDATA, 1)
row = MyDATA(i, :);
row = row(cellfun(@(x) (~isempty(x)) && (~isnumeric(x)), row));
if ~isempty(row)
idx = strfind(row, str);
idx = idx(cellfun(@(x) ~isempty(x), idx));
if ~isempty(idx)
StringFoundAt(count, :) = {i, cell2mat(idx)};
count = count + 1;
end
end
end
I hope it helps. Good luck!
5 Kommentare
sixwwwwww
am 13 Dez. 2013
Starting index means DIRs appears in the row given by Row number and at position given by Starting index. So
'Row number' 'Starting index'
4 1
means that string DIRs appears at start(because Starting index = 1) of the in row 4. Is that what you need?
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!