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
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?
Bhumi Desai
Bhumi Desai 2024-1-27
I want the code for making color graph for four variables using .csv file in MATLAB. Else which will be the suitable method for making the color graph, as I have 500 readings in .csv file. Please give me the answer.

请先登录,再进行评论。

回答(1 个)

Benjamin Thompson
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 个评论
Bhumi Desai
Bhumi Desai 2024-1-29
This graph is not smooth in coloring, it forms like different color gathering together. I want a smooth color graph like some paintings.
Walter Roberson
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 CenterFile Exchange 中查找有关 Whos 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by