How can I com[act my script by making it run up to an nth variable
Mostra commenti meno recenti
I am looking to plot multiple curves in 3D, the curves consist of 3 variables each; xn, kn and zn, such that the first curve is plotted from x1, k1 and z1. The way i am plotting the curves in 3D can be seen below and hopefuly this provides good context asto what im doing.
I have written a script that i intend to use on multiple sets of curves with varying numbers of curves, the problem parts are;
z1=rot90(v1);
z2=rot90(v2);
z3=rot90(v3);
z4=rot90(v4);
z5=rot90(v5);
z6=rot90(v6);
z7=rot90(v7);
and
plot3(x1, k1, z1, 'linewidth', 2, 'color', 'k');
plot3(x2, k2, z2, 'linewidth', 2, 'color', 'k');
plot3(x3, k3, z3, 'linewidth', 2, 'color', 'k');
plot3(x4, k4, z4, 'linewidth', 2, 'color', 'k');
plot3(x5, k5, z5, 'linewidth', 2, 'color', 'k');
plot3(x6, k6, z6, 'linewidth', 2, 'color', 'k');
plot3(x7, k7, z7, 'linewidth', 2, 'color', 'k')
grid on
surf([x1;x2], [k1;k2], [z1;z2]);
surf([x2;x3], [k2;k3], [z2;z3]);
surf([x3;x4], [k3;k4], [z3;z4]);
surf([x4;x5], [k4;k5], [z4;z5]);
surf([x5;x6], [k5;k6], [z5;z6]);
surf([x6;x7], [k6;k7], [z6;z7]);
is there a way i can get this script to create a variable called zn by rotation a variable called vn up to the nth vn variable? Is there also a similar thing i can do for plotting and drawing the surfaces as right now i am stuck with editing the script each time i am changing the number of curves. I have zero experience with coding so hopefully i have framed this well enough for it to be understandable and sorry if its just trivial.
Thanks in advance.
1 Commento
"is there a way i can get this script to create a variable called zn by rotation a variable called vn up to the nth vn variable?"
Yes there are ways, if you really want to force yourself into writing slow, complex, inefficient, insecure, obfuscated, buggy code that is hard to debug:
The simple, efficient, recommended approach is to use indexing. You should use indexing. So far there is nothing in your description and examples that would prevent you from using indexing.
Indexing is a MATLAB superpower. Use it.
Risposta accettata
Più risposte (1)
Steven Lord
il 22 Lug 2024
2 voti
Can you dynamically create variables with numbered names like z1, z2, z3, etc.? Yes.
Should you do this? The general consensus is no. That Discussions post explains why this is generally discouraged and offers several alternative approaches.
Categorie
Scopri di più su Line Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!