Having trouble in running this code. What should I do next?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
% Assuming 'saveToFile' is already defined
parts = 500;
% Read data from the CSV file
data = dlmread('2-2.csv', '\t', 1, 0);
%l = data(:, 1);
%alpha = data(:, 2);
%times = data(:, 3);
%ani = data(:, 4);
Var1 = data(:, 1);
Var2 = data(:, 2);
Var3 = data(:, 3);
Var4 = data(:, 4);
% Reshape ani and times into grids
aniGrid = reshape(ani, parts, parts)';
timeGrid = reshape(times, parts, parts)';
% Plot the aniGrid
figure('Position', [0, 0, 1000, 500]);
imagesc('XData', l, 'YData', alpha, 'CData', aniGrid);
colormap('turbo');
title('Ani');
xlabel('$l$', 'Interpreter', 'latex');
ylabel('$\alpha$', 'Interpreter', 'latex');
colorbar('Location', 'southoutside');
set(gca, 'Position', get(gca, 'Position') + [0, -0.05, 0, 0]);
if saveToFile
saveas(gcf, 'ani.png', 'png');
else
% Display the plot
drawnow; % Ensure the plot is displayed before continuing
pause(0.1); % Pause for a short time to allow the figure to be rendered
end
% Assuming 'timeGrid', 'l', 'alpha', and 'saveToFile' are already defined
figure('Position', [0, 0, 1000, 500]);
imagesc('XData', l, 'YData', alpha, 'CData', timeGrid);
colormap(turbo);
title('Time [s]');
xlabel('$t$', 'Interpreter', 'latex');
ylabel('$\alpha$', 'Interpreter', 'latex');
colorbar('Location', 'southoutside');
set(gca, 'Position', get(gca, 'Position') + [0, -0.05, 0, 0]);
if saveToFile
saveas(gcf, 'time.png', 'png');
else
% Display the plot
drawnow; % Ensure the plot is displayed before continuing
pause(0.1); % Pause for a short time to allow the figure to be rendered
end
4 comentarios
Dyuman Joshi
el 27 de En. de 2024
"The trouble is that only where I am lacking in making code. "
I don't understand what you meant here.
"I want to define the parameters."
Which parameters?
"I want the following code for this purpose."
Which purpose?
Respuestas (1)
Benjamin Thompson
el 27 de En. de 2024
Here are fixes for the first few lines so that dlmread works. But not sure what you are trying to do after that. Calling reshape with parameters of 500 and 500 means that the input vector must be 500*500=250000 in size.
% Assuming 'saveToFile' is already defined
parts = 500;
% Read data from the CSV file
data = dlmread('2-2.csv', ',', 0, 0);
%l = data(:, 1);
%alpha = data(:, 2);
%times = data(:, 3);
%ani = data(:, 4);
Var1 = data(:, 1);
Var2 = data(:, 2);
Var3 = data(:, 3);
Var4 = data(:, 4);
5 comentarios
Walter Roberson
el 29 de En. de 2024
You are displaying the output as if you had a grid that is l in one direction and alpha in the other direction. But you do not have such a grid: you have vectors l and alpha and timeGrid that are all the same length. l and alpha are each equally spaced.
The best you can do is something like
plot(l, timeGrid);
Ver también
Categorías
Más información sobre Whos 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!