Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

how to store even and odd strings into 2 seperate vectors using mod function

1 visualización (últimos 30 días)
Alex Doan
Alex Doan el 4 de Abr. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
For example Names is a 16x1
1.) a
2.) b
3.)c
4.)d
5.)e
i want to store a,c,e in variable core 1 and i want to store b,d in core 2
This is what i mean by storing the even and odd strings using mod

Respuestas (2)

Florian Floh
Florian Floh el 4 de Abr. de 2020
This code should do the trick:
names = ['c','a', 'b','z','x','s'];
oddlett = [];
evenlett = [];
[n,m] = size(names);
for i=1:m
% convert letter to corresponding index in the alphabet
ind = 1 + lower(names(i)) - 'a';
if(mod(ind, 2) ==1)
evenlett = [evenlett; names(i)];
else
oddlett = [oddlett; names(i)];
end
end

dpb
dpb el 4 de Abr. de 2020
Whassup w/ this thing about alternative storage of odd/even indices all of a sudden???
<Answers/514742-how-to-separate-an-array-into-two> altho as pointed out there first, you don't need either a loop or the mod function to do it...
>> names=cellstr(['a':'e'].');
>> n1=names(1:2:end)
n1 =
3×1 cell array
{'a'}
{'c'}
{'e'}
>> n2=names(2:2:end)
n2 =
2×1 cell array
{'b'}
{'d'}
>>

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by