Azzera filtri
Azzera filtri

Error using () Subscripting into a table...

3 visualizzazioni (ultimi 30 giorni)
Hi all, just updated to R2023 in order to use the "combinations" function, and all of sudden another section of my code no longer works. It seems like Matlab is misinterpreting "dot(" (for dot product) as a variable? I provides this error message:
Error using ()
Subscripting into a table using one subscript (as in t(i)) is not supported. Specify a row subscript and a variable subscript, as
in t(rows,vars). To select variables, use t(:,i) or for one variable t.(i). To select rows, use t(i,:).
Error in dot (line 29)
a = a(:);
Error in hw4_problem4 (line 41)
dot( ...
I haven't named any variable as dot, obviously. The code for this section is below.
for n = 1:(number_of_vectors)
for o = 1:(number_of_slip_directions)
for p = 1:(number_of_slip_planes)
schmid_factor(n,o,p) = ( ...
dot( ...
stress_vectors(n,:), ...
slip_planes(p,:) ...
) ...
/ ...
sqrt( ...
dot(stress_vectors(n,:),stress_vectors(n,:)) ...
* ...
dot(slip_planes(p,:),slip_planes(p,:)) ...
) ...
)...
*...
( ...
dot( ...
stress_vectors(n,:), ...
slip_directions(o,:) ...
)...
/ ...
sqrt( ...
dot(stress_vectors(n,:),stress_vectors(n,:)) ...
*...
dot(slip_directions(o,:),slip_directions(o,:)) ...
) ...
);
end
end
end
  1 Commento
JORDAN
JORDAN il 17 Ott 2023
Guess I'll post the full code here, just in case.
clear;clc;close all
%% Vector Setup
% This section inputs all of the vectors for the applied stress, the slip
% directions, and the slip plane normals vectors.
stress_vectors = unique(combinations([0 1 -1 1/2 -1/2],[0 1 -1 1/2 -1/2],[0 1 -1 1/2 -1/2]));
slip_directions = [ 1 1 0
-1 -1 0
1 0 1
-1 0 -1
0 1 1
0 -1 -1];
slip_planes = [ 1 1 1
-1 -1 -1];
%% Counting
% This section finds how many vectors of each type there are for later
% calculations.
[number_of_vectors,dimensions1] = size(stress_vectors);
[number_of_slip_directions,dimensions2] = size(slip_directions);
[number_of_slip_planes,dimensions3] = size(slip_planes);
%% Schmid Factor Calculation
% This section calculates Schmid's Factor for each direction of applied
% stress. Schmid's Factor is found by multiplying two quantities: the first
% quantity is the dot product of the applied stress vector and the plane
% normal vector divided by the product of the magnitudes of each vector,
% and the second quantity is the dot product of the applied stress and the
% slip direction vector divided by the product of each vector's magnitude
schmid_factor = zeros(number_of_vectors,number_of_slip_directions,number_of_slip_planes);
for n = 1:(number_of_vectors)
for o = 1:(number_of_slip_directions)
for p = 1:(number_of_slip_planes)
schmid_factor(n,o,p) = ( ...
dot( ...
stress_vectors(n,:), ...
slip_planes(p,:) ...
) ...
/ ...
sqrt( ...
dot(stress_vectors(n,:),stress_vectors(n,:)) ...
* ...
dot(slip_planes(p,:),slip_planes(p,:)) ...
) ...
)...
*...
( ...
dot( ...
stress_vectors(n,:), ...
slip_directions(o,:) ...
)...
/ ...
sqrt( ...
dot(stress_vectors(n,:),stress_vectors(n,:)) ...
*...
dot(slip_directions(o,:),slip_directions(o,:)) ...
) ...
);
end
end
end
%% Finding the number of non-zero slip systems per applied stress vector
% This section counts the number of Schimd's Factors per applied stress
% vector that don't equal zero, then appends that number to the original
% set of stress vectors for use in an fprintf function that outputs a
% statement listing the number of slip systems per applied stress vector.
non_zero_slip_systems = zeros(number_of_vectors,1);
for q=1:number_of_vectors
non_zero_slip_systems(q,1) = numel(find(schmid_factor(q,:,:) ~= 0));
end
applied_stress_and_system_count_matrix = sortrows([stress_vectors,non_zero_slip_systems],4);
formatSpec = 'Applied stress vector [%1.0f %1.0f %1.0f] has %1g slip systems\n';
%% ANSWERS
fprintf(formatSpec,(applied_stress_and_system_count_matrix'))

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 17 Ott 2023
You are passing a table() object as a parameter to dot()
It looks like either stress_vectors or else slip_panes is a table() object.
  1 Commento
JORDAN
JORDAN il 17 Ott 2023
Oh, duh. I didn't examine the combinations function output very well, I'm surprised that it generated a table... guess I'll try to sort that out. Thank you for the quick reply, this is my first time posting despite having used MATLAB for a couple of years and I wasn't sure how long it would take.

Accedi per commentare.

Più risposte (1)

Steven Lord
Steven Lord il 17 Ott 2023
Line 29 of the dot.m included with MATLAB doesn't match what you showed. MATLAB Answers uses release R2023b (Update 2, but I don't believe dot.m has changed in the 23b Update releases.)
version
ans = '23.2.0.2410171 (R2023b) Update 2'
dbtype 25:35 dot.m
25 end 26 tc = sum(conj(ta).*tb,dim); 27 end 28 end 29
I suspect you've defined your own dot.m that's taking precedence over the one included with MATLAB. To check, see what this command displays:
which -all dot
/MATLAB/toolbox/matlab/specfun/dot.m /MATLAB/toolbox/matlab/bigdata/@tall/dot.m % tall method /MATLAB/toolbox/parallel/gpu/@gpuArray/dot.m % gpuArray method /MATLAB/toolbox/parallel/parallel/@codistributed/dot.m % codistributed method
  2 Commenti
Walter Roberson
Walter Roberson il 17 Ott 2023
MATLAB Version: 23.2.0.2365128 (R2023b)
has the call to with a(:) at line 29 of toolbox/matlab/specfun/dot.m
Steven Lord
Steven Lord il 17 Ott 2023
Hmm. You're right. Ah, I'm guessing that dbtype call displayed a different dot.m than I expected.
dbtype 25:35 toolbox/matlab/specfun/dot.m
25 if nargin == 2 26 27 if isvector(a) && isvector(b) 28 % Special case: A and B are vectors and dim not supplied 29 a = a(:); 30 b = b(:); 31 if length(a) ~= length(b) 32 error(message('MATLAB:dot:InputSizeMismatch')); 33 end 34 if isreal(a) && isreal(b) 35 c = a'*b;
It looks like instead dtype displayed the overload of dot for tall arrays.
dbtype 1:5 dot.m
1 function tc = dot(ta,tb,dim) 2 %DOT Vector dot product for tall arrays. 3 % C = DOT(A,B) 4 % C = DOT(A,B,DIM) 5 %

Accedi per commentare.

Categorie

Scopri di più su Scripts 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