Help solve an error in displaying data
Mostra commenti meno recenti
Hello,
So to preface this, I am pretty new with MatLab and got some help from an AI friend. I have a script that loads a .csv file and creates a plot showcasing the intesity of a transcription start site (TSS) over the course of 24 hours. Now since I don't want to do that manually for 250 cells, I tried to automate the process so once I start my script, I get figures for all my files without having to manually import data for each new cell.
I got the script running but I can't seem to figure out how to make the script find the right TrackID (Which should be column 2 in the csv) and the Intensity (which should be column 12). Can anyone figure out why I still get empty figures when running the script?
Attached I have included an example-csv file.
Thank you.
% Specify the folder containing your files
folderPath = 'insert file path here';
saveFolderPath = 'insert desired save path here';
% Get a list of all files in the folder
files = dir(fullfile(folderPath, 'export*.csv')); % Assuming filenames start with 'export' and have a '.csv' extension
for l = 1:length(files)
% Get the current file name
currentFile = files(l).name;
% Extract values of z and w from the filename
[~, fileName, ~] = fileparts(currentFile);
parts = strsplit(fileName, '_');
z = str2double(parts{3}(3:end));
w = str2double(parts{4}(2:end));
% Load data from the current file
A = readtable(fullfile(folderPath, currentFile));
%import table values on matlab
Str=importdata(currentFile);
A=Str.data(:,:);
%i=line in the table
% Determine the column indices for TrackID and Intensity based on the data structure
trackIDColumn = 2; % Adjust this based on the actual structure of your data
intensityColumn = 12; % Adjust this based on the actual structure of your data
% Initialize variables
j = 0;
x0 = [];
k = 0;
x1 = [];
notvalid = 0;
sz = size(A);
% Loop through the data
for i = 1:sz(1)
if A(i, trackIDColumn) == z
j = j + 1;
x0(j, 1) = A(i, 7); % time 0
x0(j, 2) = A(i, intensityColumn); % intensity 0
elseif A(i, trackIDColumn) == w
k = k + 1;
x1(k, 1) = A(i, 7); % time 1
x1(k, 2) = A(i, intensityColumn); % intensity 1
else
notvalid = notvalid + 1;
end
end
% Rest of your existing script...
MS2 = zeros(481, 2);
for TrackID = 0:200
temp = A(A(:, trackIDColumn) == TrackID, [7, intensityColumn]);
MS2(temp(:, 1) + 1, TrackID + 1) = temp(:, 2);
end
% Check if w+1 is a valid index for MS2
if w+1 >= 1 && w + 1 <= size(MS2, 2)
MS2_mirror = -MS2(:, w + 1); % Adjusted for 'w'
MS2_mirror = -MS2(:, w + 1); % Adjusted for 'w'
timeframe = (1:481)';
time = timeframe * 3 - 3;
% TSS1=MS2(:,z),
% Plot
plot(time, MS2(:, z + 1), 'DisplayName', ['TSS 1']) % Adjusted for 'z'
hold on
plot(time, MS2_mirror, 'DisplayName', ['TSS 2']) % Adjusted for 'w'
xlabel('Time (min)', 'FontSize', 10)
xlim([0 1440])
ylabel('Fluorescent intensity', 'FontSize', 10)
legend(['TSS 1'], ['TSS 2'])
else
disp(['Invalid TrackID for w: ' num2str(w)]);
end
% Optionally, you can include a pause or any other necessary delay here
pause(0.5); % Adjust as needed
% Save the figure as JPEG
figJPEGName = fullfile(saveFolderPath, ['Figure_' num2str(z) '_and_' num2str(w) '_' fileName '.jpg']);
saveas(gcf, figJPEGName, 'jpeg');
% Save the figure as MATLAB Figure file
figMatName = fullfile(saveFolderPath, ['Figure_' num2str(z) '_and_' num2str(w) '_' fileName '.fig']);
saveas(gcf, figMatName, 'fig');
% Optionally, you can include a pause or any other necessary delay here
pause(0.5); % Adjust as needed
% End of the loop
close(gcf); % Close the current figure to avoid overlapping in the next iteration
end
% Additional cleanup or finalization code can be added here
disp('Processing complete.');
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su External Language Interfaces in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
