Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Concatinate datasets with the same first x letters in a workspace

1 vue (au cours des 30 derniers jours)
Daniel Gardner
Daniel Gardner le 24 Juil 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have several thousand datasets in my workspace and I want to concatenate (maybe using vertcat?) those with variable names that have the same first x letters together. Any ideas on how to do this?
  1 commentaire
Jasmine
Jasmine le 24 Juil 2014
How is the data saved? I'm assuming as a string. You could do something like this for each dataset if count is how many different dataset you have:
cnt = 1
for j=1:count
for i=1:5
if i==1
a = dataset(i)
else
if dataset(i) == a
if i == 5
finaldataset(cnt,:) = dataset
end
end
end
end
end
I think this will simply list all those datasets which the first 5 letters are the same (completely untested literally just written it here). If you need to have, say, all those which start with 5 As in a different variable than all those that start with 5 Bs, you'll need to add this in somehow. At the moment the best method I can think of is a switch-case statement for each letter of the alphabet. But this would be time consuming so maybe someone else can suggest a better method.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by