I'm plotting stress trajectories for simply supported rectangular beam under UDL. Attaching the code and it's output. Help me sort out the error & get correct trajectories.

data = readtable('data.xlsx');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
%here data is name of excel file from which i'm importing data of x,y grid & principal angles
x = data.x;
y = data.y;
theta1 = data.('Theta1');
theta2 = data.('Theta2');
%% ===== Build structured grid =====
xu = x; % unique x-values
yu = y; % unique y-values
Nx = length(xu);
Ny = length(yu);
% Create 2D mesh
[X, Y] = meshgrid(xu, yu);
size(theta1)
ans = 1×2
77 1
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Nx*Ny
ans = 5929
%% ===== Reshape angles into matrices =====
Theta1 = reshape(theta1, Ny, Nx); % IMPORTANT: Ny rows, Nx cols
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for that dimension.
Theta2 = reshape(theta2, Ny, Nx);
%% ===== Compute direction vectors =====
U1 = cos(Theta1); V1 = sin(Theta1);
U2 = cos(Theta2); V2 = sin(Theta2);
%% ===== Create seeding points =====
[startX, startY] = meshgrid( linspace(min(xu),max(xu),8), ...
linspace(min(yu),max(yu),8) );
startX = startX(:);
startY = startY(:);
%% ===== Plot Trajectories =====
figure; hold on;
% Principal direction 1
streamline(X, Y, U1, V1, startX, startY);
% Principal direction 2
streamline(X, Y, U2, V2, startX, startY);
quiver(X, Y, U1, V1, 0.5, 'k'); % direction field (optional)
axis equal tight;
xlabel('X'); ylabel('Y');
title('Stress Trajectories For Simply Supported Steel Beam');
grid on;

3 Comments

theta1 is 77x1, Nx*Ny equals 5929. No way to reshape because 77*1 doesn't equal 5929 (see above).
i have attached the data sheet in comment below if you can help me how to plot stress trajectories using that data

Sign in to comment.

Answers (0)

Categories

Asked:

on 30 Nov 2025

Commented:

on 1 Dec 2025

Community Treasure Hunt

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

Start Hunting!