function t_A2_5()
s_names = {'nimisha' 'pooja' 'leela' 'jk'}
s_marks = [23 56 78 89]
n1 = numel(s_marks)
in_st.name = [];
in_st.marks = [];
for c1 = 1: n1
A.name = s_names {c1 };
A.marks = s_marks (c1 );
in_st(c1) = A;
clear A;
end;
clear c1;
c_name = 'pooja'
ind = Get_Data(s_names,c_name);
c_data = s_marks(ind)
disp(c_data)
return;
function ind = Get_Data(s_names , c_name)
ind=find(ismember(s_names,c_name))
In this i want such that whatever i give as c_name = pooja at 17th line, then it should give corresponding answer., it is compulsory for me to make Get_Data function.. Why this erro.?

 Réponse acceptée

Orion
Orion le 22 Nov 2014
For what I understand.
you have a cell list and a 'matching' array
s_names = {'nimisha' 'pooja' 'leela' 'jk'}
s_marks = [23 56 78 89]
If you ask for 'pooja', you just want to find the corresponding element in s_names, then the corresponding value in s_marks ? your code already did it. and there is no empty matrix !
In a simplier way, you should code more like this :
s_names = {'nimisha';'pooja';'leela';'jk'};
s_marks = [23 56 78 89];
c_name = 'pooja';
c_data = s_marks(strcmp(s_names,c_name));
disp(c_data)
56

7 commentaires

Nimisha
Nimisha le 22 Nov 2014
Modifié(e) : Nimisha le 22 Nov 2014
But it is compulsory for me to make atleast one function
Get_Data
in program. in above my said program just i have to make Get_Data function
then do a function
function c_data = Get_Data(s_names,s_marks,c_name)
c_data = s_marks(strcmp(s_names,c_name));
and use it in the main
s_names = {'nimisha';'pooja';'leela';'jk'};
s_marks = [23 56 78 89];
c_name = 'pooja';
c_data = Get_Data(s_names,s_marks,c_name);
function t_A2_5()
s_names = {'nimisha'; 'pooja'; 'leela'; 'jk'}
s_marks = [23 56 78 89]
n1 = numel(s_marks);
in_st.name = [];
in_st.marks = [];
for c1 = 1: n1
A.name = s_names {c1 };
A.marks = s_marks (c1 );
in_st(c1) = A;
clear A;
end;
clear c1;
c_name = 'pooja'
c_data = Get_Data(s_names,s_marks,c_name)
disp(c_data)
return;
And i used following function
function c_data = Get_Data(s_names,s_marks,c_name)
c_data = s_marks(strcmp(s_names,c_name));
This gives output as
c_data =
Empty matrix: 1-by-0
i think its wrong.. answer should be 56
I just copy/paste your code and run it without modification and it gives
c_data =
56
So it works on my machine, I guess you have modify something on your side.
i checked..
See first line..
i made two codes,
one with
function t_A2_5()
as a starting.
When i use it i got answer,
c_data =
Empty matrix: 1-by-0
when i run code after removing it, i am getting correct answer
56
Is it anyhow possible to get correct answer
56
with using
function t_A2_5()
this as a starting.
Orion
Orion le 22 Nov 2014
I still don't get your "empty problem".
I attached the 2 Mfiles, which works for me.
just run t_A2_5 and it should work
I dont know why,
But this your given files Worked for me.
THANK YOU so much :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by