|
I am currently trying to build a structure array about a list of student names which i import from excel. The list which i import is a two column array; column 1 is students name, column 2 is their grade. I am trying to set up a system so that i can call up their grades when their name appears in any subsequent array. So for example i would like to have:
I managed to get the following script to work for names like 'Bob' and 'Steve' but i've hit a major roadblock when it comes to character spaces between first and second names such as 'John Doe'.
%%%
s(length(textdata)).student=[textdata]
C=char(textdata)
x=1
while x<=length(textdata)
s(x).student=C(x,:)
s(x).(deblank(C(x,:)))=data(x)
x=x+1
end
fn = fieldnames(s)
C=char(deblank(textdata))
out1 =[];
x=1
while x<=length(textdata)
newrow=[s.(deblank(C(x,:)))]
out1=[out1;newrow]
x=x+1
end
out1
data(:,2)=(out1)
%%%%
Any ideas how to overcome this "invalid field name" issue without having to trawl through the datasets manually pulling out character spaces??
|