How to insert a row into multiple fields (within a structure)
21 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Christopher Wallace
2018-7-16
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 个评论
更多回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!