Having trouble in running this code. What should I do next?
2 次查看(过去 30 天)
显示 更早的评论
% 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 个评论
Dyuman Joshi
2024-1-27
"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?
回答(1 个)
Benjamin Thompson
2024-1-27
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 个评论
Walter Roberson
2024-1-29
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);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!