Plotting data excel into matlab

I have two column in excel I want to plot them by using matlab, lets say I have first column from B2-B702 and second column from C2-C702. Column B is a number (age) while column C is string (tamoxifen / none treatment). I want to plot the age range data based on tamoxifen treatment or not and see the amount of patient based on the age range. How could I plot them in MATLAB ?? please help..

 Accepted Answer

Read in the data into matlab using xlsread, then plot them once they are read into the MATLAB workspace
doc xlsread
doc plot

5 Comments

Tq for the help. I can read the data but to plot it cant. This is what I typed
x = age (:,1); y = treatment (:,2); plot (x,y) ??? Error using ==> plot Conversion to double from cell is not possible.
What does it means? My sample data is
_AGE_ _TAMOXIFEN TREATMENT_
  1. 24 NO
  2. 24 NO
  3. 29 NO
  4. 29 NO
  5. 32 NO
  6. 32 NO
  7. 32 NO
  8. 32 NO
  9. 34 YES
  10. 34 YES
  11. 36 YES
  12. 36 YES
  13. 37 YES
How do I want to plot this data based on tamoxifen treatment and age? TQ
Well, Treatment is either Yes or No, so of course you cannot plot that. Plot only works with numbers. You can assign a numeric value to them, such as 1 and 0 then plot the age vs treatment which would be a series of 0s and 1s
Do you mean that I need to assign numeric value in excel or in matlab? Can u give me some example regarding on this matter?
Either one, generally people don't like to change the raw data itself, excel in this case. So something along the lines of
y = strrep(y,'YES','1')
y = strrep(y,'NO','0')
y = str2double(y)
This would convert all instances of NO to 0, and all instance of YES to 1 so you can then plot it
hye thank you for the example. I've tried to replace the string with number. It works but in command window only. When I checked at the workspace and click at TAM_TREATMENT it still show NaN. How I want it convert the num directly into my excel file? I'm sorry since this is my first time using matlab. All of it seem new to me. This is what I've typed
A = xlsread ('Data.xlsx')
[A, headertext] = xlsread ('Data.xlsx')
y = headertext(TAM_TREATMENT)
y = headertext(1:end, 12)
y = strrep (y, 'YES', '1')
y= strrep (y, 'NO', '0')
y = str2double(y)
x=AGE
plot (x,y)
??? Error using ==> plot
Vectors must be the same lengths.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!