How to iterate over data sets?
12 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone,
I am new to coding so please bare with me as I am trying my best.
I am trying to plot and iterate over different data sets, for example, I want to plot data points 1-10, skip over 11 and 12, and then plot the next 10, 13-23 and so on and so forth. This is what I have so far. Please let me know where I have gone wrong. Thank you.
filename = "Mydatasheet.csv";
opts = detectImportOptions('filepath\Mydatasheet.csv','.csv');
T = readtable("Mydatasheet.csv",opts);
dummy1 = table2array(:,1);
dummy2 = table2array(:,2);
for ii= 1: length(dummy,2)
plot(dummy1(1:10:230),dummy2(1:10:230));
end
0 件のコメント
回答 (2 件)
Star Strider
2024 年 6 月 17 日
編集済み: Star Strider
2024 年 6 月 17 日
dummy1 = (1:60).'
bfr1 = buffer(dummy1, 12);
disp(bfr1)
dummy1_out = bfr1(1:10,:)
Otherwise, you can creatre your own limited version of it, for example —
bfr2 = bufr(dummy1, 12);
disp(bfr2)
dummy1_out = bfr2(1:10,:)
function M = bufr(s,r)
% Star Strider's Emulation Of The Basic 'buffer' Function
% s = Signal Vector
% r = Desired number of rows
M = zeros(r,ceil(numel(s)/r));
M(1:numel(s)) = s;
end
EDIT — Corrected typographical errors.
EDIT — (17 Jun 2024 at 21:10)
Use the reshape functon to restore the edited ‘dummy1_out’ matrix to a column vector afterwards, so —
dummy1_out = reshape(dummy1_out, [],1);
disp(dummy1_out)
.
0 件のコメント
Hassaan
2024 年 6 月 17 日
編集済み: Hassaan
2024 年 6 月 17 日
An initial idea adjust as per your data format and requirements.
Better to share your .csv file.
% Load data from the CSV file
filename = "Mydatasheet.csv";
opts = detectImportOptions(filename); % Corrected path
T = readtable(filename, opts);
% Convert table to array
dataArray = table2array(T);
% Separate columns for X and Y data
dummy1 = dataArray(:, 1); % Assuming first column is X data
dummy2 = dataArray(:, 2); % Assuming second column is Y data
% Initialize figure
figure;
hold on; % Hold on to plot multiple segments on the same figure
% Iterate over the data in chunks
chunkSize = 10; % Number of points in each segment
skipIndices = [11, 12]; % Indices to skip
for startIdx = 1:chunkSize+length(skipIndices):length(dummy1)
endIdx = startIdx + chunkSize - 1;
% Ensure we don't exceed the array bounds
if endIdx > length(dummy1)
endIdx = length(dummy1);
end
% Plot the current segment
plot(dummy1(startIdx:endIdx), dummy2(startIdx:endIdx), 'DisplayName', ['Segment ' num2str(startIdx)]);
end
% Add labels and legend
xlabel('X Data');
ylabel('Y Data');
title('Plot of Data Segments');
legend show;
hold off; % Release the hold
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!