MATLAB Answers

0

How to insert a row into multiple fields (within a structure)

Asked by Mathew Grey on 16 Jul 2018
Latest activity Answered by Mathew Grey on 17 Jul 2018
Hi All,
My code looks as follows:
clear all;
close all;
clc
[~, Sheets] = xlsfinfo('GPSdata2018copy.xlsx');
nSheets = length(Sheets);
Data =[]
GPS = struct
for i = 1:nSheets
Player = Sheets{i};
[Data,~,Raw] = xlsread('GPSdata2018copy.xlsx', Player, 'E8:KE16');
Dates = datetime(Data(1,:),'convertfrom','excel');
Data(1,:) = datenum(Dates);
GPS = setfield(GPS, Player, Data);
end
I want to add a row to each of my fields in the second row under the dates without removing any of the data that is in there (just moving the data down). Can someone please tell me how to do that? Do I do it in the loop, our have to do it to the Data that I read over?
Kind regards, Mat

  1 Comment

Mat,
Please attach your data file as well.

Sign in to comment.

Products


Release

R2017b

3 Answers

Answer by Christopher Wallace on 16 Jul 2018
 Accepted Answer

Mat,
I've created dummy data that from what you're saying is similar in structure to what you use.
The result of the code ends up like this:
You want to add a single row to the top of the field value array?
If so it can be done in the loop using something like this:
Dates = datetime(Data(1,:),'convertfrom','excel');
Data(1,:) = datenum(Dates);
Data = [Data(1, :); zeros(1, size(Data, 2)); Data(2:end, :)];
GPS = setfield(GPS, Player, Data);

  0 Comments

Sign in to comment.


Answer by Mathew Grey on 16 Jul 2018

Hi Christopher,
Thanks for the reply. I am really sorry but unfortunately the data file contains confidential information that I cannot release. The above code works for the data and creates a structure with a field for each player. Inside the fields contains a data matrix for each player with the same dimensions (9 x 287). I wish to add a single row to each of the fields (in row 1) that I will fill with an outside formula (that isn't in the data file). Can you please help?

  0 Comments

Sign in to comment.


Answer by Mathew Grey on 17 Jul 2018

Thank you Christopher! That is perfect

  0 Comments

Sign in to comment.