How to iterate over data sets?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Star Strider
el 17 de Jun. de 2024
Editada: Star Strider
el 17 de Jun. de 2024
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 comentarios
Hassaan
el 17 de Jun. de 2024
Editada: Hassaan
el 17 de Jun. de 2024
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 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!