How can i get this function to work with this spreadsheet

function [L,B,C] = xyz2lbc(Xc,Yc,Zc,R)
if( (length(Xc) ~= length(Yc)) | (length(Xc) ~= length(Zc)) )
error('size');
end
if(nargin == 3)
R = zeros(1,length(Xc)-2);
elseif(length(R) == 1)
R = ones(1,length(Xc)-2).*R;
elseif(length(R) ~= length(Xc)-2)
error('R not match');
end
for i = 1:length(Xc)-2
V1 = [Xc(i)-Xc(i+1) ; Yc(i)-Yc(i+1) ; Zc(i)-Zc(i+1)];
V2 = [Xc(i+2)-Xc(i+1) ; Yc(i+2)-Yc(i+1) ; Zc(i+2)-Zc(i+1)];
V1l = Vlength(V1);
V2l = Vlength(V2);
C(i) = pi - acos(dot(V1,V2) / (V1l*V2l));
planeV(i,:) = cross(V1,V2)';
if(i>1)
Y(i) = Y(i) - R(i)*tan(C(i)/2);
Y(i+1) = V2l - R(i)*tan(C(i)/2);
PV1l = Vlength(planeV(i-1,:));
PV2l = Vlength(planeV(i,:));
s=sign(V1 .* cross(planeV(i-1,:),planeV(i,:))');
B(i) = acos(dot(planeV(i-1,:),planeV(i,:))/(PV1l*PV2l))*s(1);
else
Y(i) = V1l - R(i)*tan(C(i)/2);
Y(i+1) = V2l - R(i)*tan(C(i)/2);
B(i) = 0;
end
end

2 commentaires

Guillaume
Guillaume le 24 Juil 2017
Modifié(e) : Guillaume le 24 Juil 2017
It's unclear what you are asking.
On the one hand, we have a function with a meaningless name using variables with also meaningless names and absolutely no comment, so it's impossible to know what it's supposed to do. One thing is clear, it has nothing to do with spreadsheet
On the other hand, we have a spreadsheet (which we would have to download and open to even know what's in it).
No idea how the two relate to each other.
edit: and to top it off, the function defines its first output as L, yet never assigns anything to it, so it will result in an error every time it is called.
Stephen23
Stephen23 le 24 Juil 2017
Modifié(e) : Stephen23 le 24 Juil 2017
@Guillaume: it is clearly a super-secret test of super-intelligence, and anyone who cracks this super-cryptic question wins!

Connectez-vous pour commenter.

 Réponse acceptée

The xls file has values for Xc, Yc and Zc. You have to read it (using xlsread) and call your function. The other argument (R) you can ignore in the call. If it is ignored, it is generated by the function automatically.
%%Import the data
[~, ~, raw] = xlsread('TABLE.xls','TABLE');
raw(cellfun(@(x) ~isempty(x) && isnumeric(x) && isnan(x),raw)) = {''};
%%Replace non-numeric cells with NaN
R = cellfun(@(x) ~isnumeric(x) && ~islogical(x),raw); % Find non-numeric cells
raw(R) = {NaN}; % Replace non-numeric cells
%%Create output variable
data = reshape([raw{:}],size(raw));
%%Allocate imported array to column variable names
Xc = data(:,1);
Yc = data(:,2);
Zc = data(:,3);
[L,B,C] = xyz2lbc(Xc,Yc,Zc);%Call the function

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by