how to save array in different dimension

Greetings!
I have a loop that calculates ri:
for i = 1:length(x)
ri(i)=sqrt(((x(i)-xs)*111.1)^2)+(((y(i)-ys)*85.3)^2)+((z(i)-zs)^2);
end
Output is an array 1x77, but I need 77x1.
I tried, ti==array 77x1
if isequal(indt,ri)==0;
ri=transpose(ri);
end
But it didn't work.
I'm new to MatLAB and can not find a way how to solve it, anyone can help me please?

2 Comments

please define your input variable x,xs,y,ys,z,zs or attach your data.
if your output ri is 1*77 array just use transpose.
ri=randi(10,1,77);
output=ri'
output = 77×1
8 3 1 3 6 10 7 8 3 8
Sorry I forgot to mention that transpose works for me, but since this code is going to be a part of another loop, every 2nd time it transposes back, I need to avoid this behaviour.
My code is :
load('WBCZE1.mat');
x=WBCZE1.longitude; y=WBCZE1.latitude; z=WBCZE1.depth; t=datenum(WBCZE1.Origin_time);
xnan = isnan(x); ynan = isnan(y); WBCZE1(xnan,:) = []; WBCZE1(ynan,:) = []; x(xnan,:) = []; y(ynan,:) = []; %remove NaN
xs=x(2); ys=y(2); zs=z(2); ts=t(2); %picking point by index
%I have to set time window Tmax, in days
Tmax = 760;
indt = find(t>=ts-(Tmax/2) & t<=ts+(Tmax/2)); % Tmax indexes
Tmstart =indt(1); Tmstop = indt(end);
x=x(Tmstart:Tmstop); y=y(Tmstart:Tmstop); z=z(Tmstart:Tmstop); t=t(Tmstart:Tmstop);
%and then initial code
% calculation of the distance from the selected point to all other points in the area
for i = 1:length(x)
ri(i)=sqrt(((x(i)-xs)*111.1)^2)+(((y(i)-ys)*85.3)^2)+((z(i)-zs)^2);
end

Sign in to comment.

 Accepted Answer

KSSV
KSSV on 17 Feb 2022
Edited: KSSV on 17 Feb 2022
REad about initializing.
ri = zeros(length(x),1) ;
for i = 1:length(x)
ri(i)=sqrt(((x(i)-xs)*111.1)^2)+(((y(i)-ys)*85.3)^2)+((z(i)-zs)^2);
end
If you want to transpose, just use:
ri = ri.' ;

More Answers (0)

Products

Release

R2020b

Asked:

on 17 Feb 2022

Edited:

on 17 Feb 2022

Community Treasure Hunt

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

Start Hunting!