how to code for this problem??

i have Names with subject marks as labels(column wise) and values(double) in excel file,like NAME SUBJECT_1 SUBJECT_2.....upto SUBJECT_50.
but for some analysis,i need to fetch few subject values(15 subjects) with respect to name. my selected subjects labels will be given in header.txt.(wt ever subject label i give in this header.txt,my program should fetch that subject column data's alone and store in separate file). any help or suggestion for this concept??..............need help here

回答 (1 件)

Image Analyst
Image Analyst 2013 年 10 月 28 日

0 投票

Try this (untested):
[num, txt, raw] = xlsread(fullFileName); % Read in Excel file.
[rows, columns] = size(txt);
% Get random numbers
filesToSelect = randperm(rows, 15);
% Select 15 random filenames from the whole list.
selectedStrings = txt(filesToSelect, :);
% Now open headers.txt and pull out those
fid = fopen('headers.txt');
tline = fgetl(fid);
counter = 1;
while ischar(tline)
disp(tline)
% Get next line.
tline = fgetl(fid);
% Save it as a header line.
headers{counter} = tline;
end
% Extract just those we want.
headers = headers{selectedStrings);
fclose(fid);

6 件のコメント

sandy
sandy 2013 年 10 月 30 日
its not working..randperm() syntax showing error..i couldnt go further..
Image Analyst
Image Analyst 2013 年 10 月 30 日
You must have a really old version of MATLAB. Try this instead:
filesToSelect = randperm(rows); % Get all numbers scrambled.
filesToSelect = filesToSelect (1 : 15); % Take 15 of them.
sandy
sandy 2013 年 10 月 30 日
編集済み: sandy 2013 年 10 月 31 日
thanks...what i need is..if i give the names of required subject names like (ex:SUBJECT_1 SUBJECT_4 SUBJECT_9 SUBJECT_23) in a header.txt(4*1) file,it should compare with the headers (ex:SUBJECT_1 SUBJECT_2.. SUBJECT_50)which is in sample.xlsx(200*50) (below each SUBJECT many values will be present(column wise))and copy the matched subjects values to another variable as(200*4)
Image Analyst
Image Analyst 2013 年 10 月 31 日
Use ismember().
sandy
sandy 2013 年 10 月 31 日
thanks..using ismember() can find which column matched subject,but how to get the values below (only for matched subjecdt name)??
Image Analyst
Image Analyst 2013 年 10 月 31 日
Yes. It works on cell arrays of strings. Just look over the documentation and try it.
ca = {'SUBJECT_1'; 'SUBJECT_4'; 'SUBJECT_9'; 'SUBJECT_23'; 'SUBJECT_4'}
lookingFor = 'SUBJECT_4'
matchingLogicalIndexes = ismember(ca, lookingFor)
matchingRowNumbers = find(matchingLogicalIndexes)
In the command window:
ca =
'SUBJECT_1'
'SUBJECT_4'
'SUBJECT_9'
'SUBJECT_23'
'SUBJECT_4'
lookingFor =
SUBJECT_4
matchingLogicalIndexes =
0
1
0
0
1
matchingRowNumbers =
2
5

この質問は閉じられています。

質問済み:

2013 年 10 月 28 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by