Adjusting table columns by a grouped value
조회 수: 1 (최근 30일)
이전 댓글 표시
When working with my dataset, I find that I need to adjust the data in ways that makes the plots more understandable. In this particular example, I'm trying to adjust the times in a table by finding the minimum value for every run, then subtracting the minimum value to every run so that each run in my dataset all start at t=0 on a plot.
I can find the mimium value, and have created a table with those values, however I am not sure how to apply these values to the main table, so that I can create an additional column with the adjusted time. I believe it has something to do with rowfun, but I can't figure out how to get around the different sizes of the rows to get a proper calculation. I will be adding what I have so far in an attachment. Thank you.
EDIT:
If it'll make any sense, I'm trying to do something akin to this in the code:
adjtfcn= @(times,mintime)(minus(times,mintime));
test.adjtimes=rowfun(adjtfcn,...
test, "inputvariables", [test.times,mint.min_times],...
"groupingvariables","cycleNumber")
댓글 수: 0
채택된 답변
Star Strider
2024년 8월 23일
One optiopn is to sue findgroups and then accumarray to create the different tables. They need to be separate since they are differnt lengths. The results appear to be sorted correctly by the ‘times’ variable.
Try this —
load('test')
whos('-file','test')
mint
test
[G,id] = findgroups(test.cycleNumber);
Result = accumarray(G, (1:numel(G)).', [], @(x){test(x,:)})
Result{1}
Result{end}
.
댓글 수: 5
Steven Lord
2024년 8월 23일
There are three ways to specify the color of a line, as shown on this documentation page. There are only 8 that are named or have "short names" (red, green, blue, cyan, magenta, yellow, black, and white) but you can specify an RGB triplet or a hex color code. For example, if I want a line with a lot of blue, some red, and only a dash of green:
c = [0.4 0.1 0.9];
plot(1:10, 1:10, 'Color', c, 'LineWidth', 4) % Make it thick so it's easy to see
That's not a half bad purple. Or I could have used a hex color code. For a lot of red, some green, and only a little blue:
c = '#E08018';
figure
plot(1:10, 1:10, Color = c, LineWidth = 4)
I'd call that orange or maybe a dark mustard. [Naming colors can be tricky.]
Star Strider
2024년 8월 23일
As always, my pleasure!
Perhaps this —
load('test')
whos('-file','test')
mint
test
VN = test.Properties.VariableNames;
[G,id] = findgroups(test.cycleNumber);
Result = accumarray(G, (1:numel(G)).', [], @(x){test(x,:)});
for k = 1:numel(Result)
Result{k}.times = Result{k}.times - Result{k}.times(1);
end
% Result{1}
%
% Result{end}
cm = colormap(turbo(numel(Result)));
figure
hold on
for k = 1:numel(Result)
plot(Result{k}.times, Result{k}.EcellV, 'DisplayName',sprintf('Cycle # %2s',Result{k}.cycleNumber(1)), 'Color',cm(k,:))
end
hold off
grid
xlabel(VN{2})
ylabel(VN{3})
legend('Location','eastoutside')
Choose whatever colormap you want.
.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!