Selecting Specific Data After csvread

So I have a csv file named 'RedBullJumpData'. And I have a Matlab script with the following lines; close all; clear;
jumpdata = csvread('RedBullJumpData.csv'); t_redbull = jumpdata(:,1); v_redbull = jumpdata(:,2); terminal_velocity = jumpdata(:,3);
N_timestamps = length(t_redbull); velocity = 9.81*t_redbull; xlimits = [0, 180]; ylimits = [0, 400];
plot(t_solution, v1); xlabel('Time (sec)', 'fontsize', 24) ylabel('Velocity (m/s)', 'fontsize', 24) grid on; xlim(xlimits); ylim(ylimits);
As can be seen I have read the csv file already into the variable 'jumpdata'. I have assigned the first column values to t_solution, the second column values to v_solution and the third column values to terminal_velocity. The issue is that I am tasked to create another two variables (I'll just call them t_solution and v_solution) for a formula. However, t_solution has to read the data from the first column in the same csv file, only starting on row 16 of the csv file (row included). And v_solution has to start on row 16 (row included) and read in the data below this row in column 2. i.e. these two variables are a subset off their corresponding variables. Can someone provide the code to this please? I have tried using csvread again and then selecting the specific matrices but this fails.
Thank you very much Edmond

Answers (1)

You may want to consider the example in the csvread documentation Read Specific Range from CSV File.

4 Comments

That's not what I'm looking for. I have already read in the csv file into a variable known as 'jumpdata'. What I want is to assign a variable, for example 'example_variable', to a specific range in the csv file. What you have linked me is if I have yet to read the csv file. But I already have. What I want is to assign 'example_variable' the rows from row 16 down in the first column. The variables I have (t_redbull, v_redbull and terminal_velocity) are assigned columns 1,2 and 3 respectively. This is done by jumpdata(:,1) to assign all values in column 1 to t_redbull. What I want to know is how to do this for the variable I have (example_variable) but starting from row 16.
The assignment as you posted it says:
However, t_solution has to read the data from the first column in the same csv file, only starting on row 16 of the csv file (row included). And v_solution has to start on row 16 (row included) and read in the data below this row in column 2. i.e. these two variables are a subset off their corresponding variables.
You asked:
‘Can someone provide the code to this please?’
I directed you to the documentation that tells you how to do this. The assignment wants you to learn how to use the options csvread provides.
I know. I've read what you linked me a couple times. The problem is that since I need to csvread the entire csv file the first time, it's not letting me csvread it a second time in the same code and selecting a specific data range.
If you are absolutely certain that row 16 in your .csv file is row 16 of your data, you can simply reference it as ‘example_variable(16:end,:)’. However, the ‘More About’ section of the R2016b documentation for the csvread function mentions:
  • Skip header rows or columns by specifying row and column offsets. All values in the file other than headers must be numeric.
If there are header rows or columns, the match may not be exact. You may have to open the .csv file in a text editor to be certain. It could also be that for whatever reason, you are only supposed to use the data beginning at row 16 in the file.

Sign in to comment.

Tags

Asked:

on 7 Feb 2017

Commented:

on 8 Feb 2017

Community Treasure Hunt

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

Start Hunting!