Plotting inside structure array

3 views (last 30 days)
Saray on 18 May 2023
Edited: Askic V on 18 May 2023
Hi everyone,
I have this script for my cvs file (1680x75). I took the measuremnts every one hour for 7 days consecuitivly which is contains 13 variables which very 10 rows my data are reapeted and new data registered for every hour. Now I want to plot the Temperatura named as Tin versus Time (hours of measurment) for all these 7 days in the seperated plots. Such that I will gonna have one plot for 3rd of April for all 9 hours of measurement and other plot for 4th of april for 24 hours of measurement and so on... that finally I will have 8 plots. Also, I need to do same for imp versus Time. Could you please help me for that. Thanks in advance.

Answers (1)

Askic V
Askic V on 18 May 2023
Edited: Askic V on 18 May 2023
This may not be the most efficient way, but here is how I would do it.
I hope some of many gurus here may suggest more efficient approach. Your code is slightly modifed and the Data.csv file is assumed to be in the current folder. I made this modification so the code is not too long.
% Initialization steps:
clc; clear; close all;
workspace; % Make sure the workspace panel is showing.
format long g; format compact;
%% open files and add to dataset
k = 1;
% import the full data matrix
xx = readcell('Data.csv');
% Go through the matrix and take dates and impedance parameters
j = 0;
for i = 1:10:height(xx)
yy = xx(i,1);
%data(k).data(j).name = erase(yy," GMT+0100 (ora solare Europa occidentale)Frequency - Amplitude - Phase-Rs-Rp-Xs-Xp"); % deletes the portion of the text that is not needed
x1 = cell2table(xx(i+1:i+9,1:width(xx)));
data(k).data(j).freq = table2array(x1(1,:)).';
data(k).data(j).imp = table2array(x1(2,:)).';
data(k).data(j).phase = table2array(x1(3,:)).';
data(k).data(j).Rs = table2array(x1(4,:)).';
data(k).data(j).Rp = table2array(x1(5,:)).';
data(k).data(j).Cs = table2array(x1(6,:)).';
data(k).data(j).Cp = table2array(x1(7,:)).';
data(k).data(j).Tin = table2array(x1(8,:)).';
data(k).data(j).Tout = table2array(x1(9,:)).';
data(k).data(j).Real = data(k).data(j).imp.*(cos(data(k).data(j).phase*pi/180)); % Real
data(k).data(j).Imag = data(k).data(j).imp.*(sin(data(k).data(j).phase*pi/180)); % Imagin
data(k).data(j).date = string(yy{1}(5:15));
data(k).data(j).Time = string(yy{1}(16:24));
%% Here is the section to extract and sort data by dates
dates = [];
% use only unique dates
unique_dates = unique(dates);
numunique_dates = numel(unique_dates);
data_days(numunique_dates) = struct('Day', "", 'Time', [], 'Tin', []);
for k = 1:numunique_dates
idx = string(dates) == unique_dates(k); % Index of data with the current date
data_days(k).Day = unique_dates(k);
Tin_temp = [];
% Use only first entry in Tin, because all are the same in each day
data_days(k).Tin = Tin_temp(1,:); % Tin data for the current date
timeStrings = strcat(unique_dates(k), string([]));
data_days(k).Time = datetime(timeStrings, 'InputFormat', 'MMM dd yyyy HH:mm:ss');
plot(data_days(k).Time, data_days(k).Tin);
grid on;


Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!