Having trouble in running this code. What should I do next?

2 visualizzazioni (ultimi 30 giorni)
% 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 Commenti
Dyuman Joshi
Dyuman Joshi il 27 Gen 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?
Bhumi Desai
Bhumi Desai il 27 Gen 2024
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.

Accedi per commentare.

Risposte (1)

Benjamin Thompson
Benjamin Thompson il 27 Gen 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 Commenti
Bhumi Desai
Bhumi Desai il 29 Gen 2024
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 il 29 Gen 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);

Accedi per commentare.

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by