Parsing an array A based on trigger data in array B ?
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone!
I have what should be a simply question but I cannot seem to find an effective solution. I have two columns of data in Excel files that I read into Matlab, at the moment as two separate arrays (column A and B).
Column A contains numeric data and Column B is a trigger stamp for the data in A. Example:
What I need to do is to parse A and split it into a number of (30) arrays depending on the trigger point in B i.e. the very large A would become A1, A2, A3 ... A30, split according to when there is a data-stamp in B.
2 个评论
采纳的回答
Chad Gilbert
2013-7-3
If I save similar data out as a .csv file:
A,B
1.303,1
1.61,
4,2
1.213,
and then read them in with:
>> a = csvread('a.csv',1,0)
I get a matrix the same shape as your data, with 0's filling all the empty spots:
a =
1.3030 1.0000
1.6100 0
4.0000 2.0000
1.2130 0
This will be pretty easy to parse into a cell array of arrays.
3 个评论
Chad Gilbert
2013-7-3
编辑:Chad Gilbert
2013-7-3
Ah, I see. I thought your trouble was with reaading. To split it up, Rob's answer ought to work. Or a shorter version might be:
ind = [find(a(:,2)>0); size(a,1)+1];
b = arrayfun(@(i)a(ind(i):ind(i+1)-1),1:length(ind)-1,'uniformoutput',false)
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!