Question about columns and multiplying within new columns
2 ビュー (過去 30 日間)
古いコメントを表示
I have a problem which is slightly complicated to explain but bear with me. I recently was given data on the time and strain of a large number of particles(1500) but all the data is represented in two columns (One for time and one for strain). There are different numbers of data rows representing each particle (particle 1 may have 150 rows of data while particle 2 may have 231 rows of data). Each particle has a break of roughly 3 rows that appears as 'NaN' ( I managed to convert the NaN to zero with '(isnan(temps))=0;').
Currently I am trying to manipulate the data to create new columns that involve different values based on equations. The second step is to graph these values. So for example I am using an equation to read stress accumulation. In Excel it roughly translates into this
for i=2:N temps(i+1,8)=temps(i,8)+temps(i+1,7); end
This takes values from the previous stress accumulation and adds it to the current stress at that particular time (thus creating the new stress accumulation value for column 8). The problem I have is that I need a method of allowing the program to distinguish between different particles . All particles are on the same column so the stress is just constantly added. Any suggestions?
0 件のコメント
回答 (1 件)
Chad Greene
2017 年 7 月 20 日
Hi Owen,
I think you can do this without a loop. To take the cumulative sum, there's a built-in Matlab function called cumsum. However, if you want to reset the counter at each occurrence of NaN, use Brett Shoelson's nancumsum. It's quite brilliant. Here's an example. For this column a:
a = [1 1 1 1 nan 1 1 1 nan 1 1]'
a =
1.00
1.00
1.00
1.00
NaN
1.00
1.00
1.00
NaN
1.00
1.00
Count up all the elements as a cumulative sum, and reset the counter at every NaN:
nancumsum(a,1,4)
ans =
1.00
2.00
3.00
4.00
NaN
1.00
2.00
3.00
NaN
1.00
2.00
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Stress and Strain についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!