Having trouble in running this code. What should I do next?
3 ビュー (過去 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 で Whos についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!