Last active
December 11, 2023 16:59
-
-
Save allsey87/c749ee0d6bfa21b7dccb9b965ebc174d to your computer and use it in GitHub Desktop.
How to plot data in Scilab from a CSV file (with first line as the header)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear parse_my_data | |
clear path | |
clear inputs | |
clear index | |
function parse_my_data(f_data_path) | |
csv_data = read_csv(f_data_path); | |
num_data = strtod(csv_data(2:$,1:$)); | |
num_data_points = size(num_data,1); | |
my_plot = figure(); | |
my_plot.axes_size = [num_data_points*10 500]; | |
my_plot.background = color("white"); | |
my_plot.figure_name = fileparts(f_data_path, "fname"); | |
my_axes = my_plot.children(1); | |
my_axes.margins = [0.05,0.05,0.05,0.05]; | |
my_axes.tight_limits = "on"; | |
my_axes.data_bounds = [0, -2.0; num_data_points, 2.0]; | |
my_axes.axes_visible = ["on", "on", "off"]; | |
plot(my_axes, [num_data(1:$,1:$)]) | |
legend(my_axes, csv_data(1,1:$)) | |
endfunction | |
path = '/home/allsey87/Workspace/pid-tuning/' | |
inputs = path + findfiles(path, 'pid*'); | |
for index = 1:1:size(inputs,1) | |
parse_my_data(inputs(index)); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Thanks for sharing your code. It helped me a lot. In my case, there was only one file including multiple columns.
To create a unique plot for each column, I wrote another script using your codes. You can find my script below.
Don't forget to modify the path :)
CSV Columns to Figures
path = "/home/.../someUglyFile.csv";
csvData = read_csv(path); // Fetch data from file
numData = strtod(csvData(2:$, 1:$)); // Exclude the title row
rowCount = size(numData, 1); // Get row count
columnCount = size(numData, 2); // Get column count
// Iterate for each column
for column = 1 : columnCount
myPlot = figure(); // Create a figure
myPlot.figure_name = csvData(1, column); // Determine figure name
plot(numData(:, column)); // Plot the related data
legend(csvData(1, column)); // Adjust graph legend
end
// xdel(winsid()) // Close all figure windows