Borrar filtros
Borrar filtros

how to compare two cells and fetch the values ?

1 visualización (últimos 30 días)
sandy
sandy el 28 de Oct. de 2013
Comentada: sixwwwwww el 31 de Oct. de 2013
i have two cells,x= A,B,C,D,E,F..and y= B,E,F...if i compare this two cells,i need to the values below B,E,F to be stored to another variable...is it possible?i couldn't figure it out..
  1 comentario
dpb
dpb el 28 de Oct. de 2013
What does " the values below B,E,F" mean, precisely?

Iniciar sesión para comentar.

Respuestas (2)

sixwwwwww
sixwwwwww el 30 de Oct. de 2013
Dear Sandy, maybe you can try something like this:
x= ['A','B','C','D','E','F'];
y= ['B','E','F'];
z = reshape(intersect(x, y), [], 1);
I hope it helps. Good luck!
  7 comentarios
sandy
sandy el 31 de Oct. de 2013
Editada: sandy el 31 de Oct. de 2013
...i need code for this operation(example) in this image...code is
[num, txt, B] = xlsread('input.xlsx');
A = importdata ( 'sample.txt');
for i = 1: numel(A(1,:))
for j = 1: numel(B(1,:))
if ismember(B(1,j),A(1,i))
R(:,i) = B(:,j);
break;
end
end
end
sixwwwwww
sixwwwwww el 31 de Oct. de 2013
I assume that in your text file you have data as follows:
B E F
and in your excel file you have data as follows:
A B C D E F
1 2 3 4 5 6
2 3 4 5 6 7
3 4 5 6 7 8
4 5 6 7 8 9
5 6 7 8 9 10
Now you can read column headers from text file and read data for those column names from excel file as follow:
ID = fopen(TextFileName);
HeaderInfo = textscan(ID, '%s');
fclose(ID);
HeaderInfo = HeaderInfo{:};
[~, ~, raw] = xlsread(ExcelFileName);
ColumnHeaders = raw(1, :);
B = find(ismember(ColumnHeaders, HeaderInfo));
R = cell2mat(raw(2:size(raw,1), B));
I hope it is what you are looking for. Good luck!

Iniciar sesión para comentar.


Jos (10584)
Jos (10584) el 30 de Oct. de 2013
Use cell array of strings, so you can use all the available set functions:
y = {'A','B','F'}
x = {'A','BBB','C','D','E','F'}
intersect(x,y)
setdiff(x,y)
ismember(y,x)
union(x,y)
setxor(x,y)

Categorías

Más información sobre Text Data Preparation 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