Using eval - REALLY need help please

I'm working on some homework for school and one of the questions I have is as following:
4. Find the column that the heart rate(‘HR’) is in by searching through the data using Matlab and assign the data to its name using eval.
I've been reading through some other posts and many people are recommending not using eval, but my professor specifically said to use it. I also noticed that many codes with eval require an input of a string. I have no idea how I would use that. The Heart rate data, I've already found the location of. It's in the 24th column and the data runs from 4:end,24 in the data matrix. Is there a way I can use eval to perform what this question is asking with or without the input (preferable without)
Thanks!

 Accepted Answer

Geoff Hayes
Geoff Hayes on 7 Dec 2014
Edited: Geoff Hayes on 7 Dec 2014
Alyna - perhaps all your professor wants you to do is assign this heart rate vale to a variable if the same name. If you were to do thus without eval, then the code might be
HR = data(4:end,24);
where data is your data matrix of strings (since I am assuming that you found HR in thus row). If you were to build a string from the above command, then evaluate it with eval, the code might look something like
startrow = 4;
col = 24;
cmd = sprintf('HR = data(%d:end,%d);',startrow,col);
eval(cmd);
Running the above code should create the variable HR with the appropriate result. It may be that your teacher wants you to come up with some code that will read through your matrix and create other variables based on its contents, without you knowing what those variables are until after your code has finished. Try the above and see what happens, and be sure you verify that the heart rate data is in the correct location.

1 Comment

This worked out perfectly!! Thanks I really really appreciate it!

Sign in to comment.

More Answers (0)

Categories

Asked:

on 7 Dec 2014

Commented:

on 7 Dec 2014

Community Treasure Hunt

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

Start Hunting!