Is it possible to group some strings of code, in order to shorten the visualization of the script?

1 view (last 30 days)
I would like to goup some strings of code and be able to open and close the group for a better visualization.
For example the 'while', or the 'for' command make it possible by itself, but others (like the 'case' command) not, and the same a the simple strig whit jus data.
On matlab i can gourp this srings by defoult
while true
disp('Use the capital letter!')
GA=input('Indicate geographycal position (Nord-N, Center-C, Sud-S)','s');
if ismember(GA,{'N','C','S'})
break
end
end
But i cant do it for these ectors that are used later in my script, that i would like to group as "Profiles".
ProfileA=[0.400 0.388 0.375 0.363 0.350 0.350 0.350 0.350 0.350 0.375 0.400 0.425 0.450 0.488 0.525 0.563 0.600 0.650 0.700 0.750 0.800 0.850 0.900 0.950 1.000 0.988 0.975 0.963 0.950 0.938 0.925 0.913 0.900 0.913 0.925 0.938 0.950 0.938 0.925 0.913 0.900 0.888 0.875 0.863 0.850 0.813 0.775 0.738 0.700 0.700 0.700 0.700 0.700 0.688 0.675 0.663 0.650 0.663 0.675 0.688 0.700 0.725 0.750 0.775 0.800 0.838 0.875 0.913 0.950 0.963 0.975 0.988 1.000 0.988 0.975 0.963 0.950 0.963 0.975 0.988 1.000 0.975 0.950 0.925 0.900 0.875 0.850 0.825 0.800 0.725 0.650 0.575 0.500 0.475 0.450 0.425];
ProfileAh=[0.400 0.350 0.350 0.450 0.600 0.800 1.000 0.950 0.900 0.950 0.900 0.850 0.700 0.700 0.650 0.700 0.800 0.950 1.000 0.950 1.000 0.900 0.800 0.500];
ProfileC=[0.516 0.511 0.506 0.523 0.540 0.545 0.549 0.537 0.524 0.521 0.518 0.509 0.500 0.500 0.499 0.509 0.519 0.524 0.528 0.550 0.571 0.572 0.573 0.587 0.600 0.600 0.599 0.656 0.713 0.724 0.735 0.811 0.886 0.885 0.883 0.868 0.853 0.849 0.845 0.865 0.884 0.874 0.863 0.901 0.938 0.948 0.958 0.930 0.901 0.909 0.917 0.901 0.884 0.902 0.919 0.899 0.879 0.874 0.869 0.844 0.818 0.811 0.804 0.801 0.798 0.814 0.830 0.805 0.780 0.798 0.815 0.788 0.761 0.763 0.765 0.724 0.682 0.680 0.678 0.678 0.677 0.673 0.669 0.675 0.681 0.687 0.693 0.671 0.649 0.633 0.617 0.598 0.579 0.569 0.558 0.537];
ProfileCh=[0.516 0.540 0.524 0.500 0.519 0.571 0.600 0.713 0.886 0.853 0.884 0.938 0.901 0.884 0.879 0.818 0.798 0.780 0.761 0.682 0.677 0.681 0.649 0.579];
ProfileR=[0.246 0.260 0.274 0.277 0.280 0.282 0.284 0.285 0.286 0.294 0.301 0.301 0.301 0.299 0.296 0.299 0.302 0.314 0.325 0.328 0.330 0.362 0.393 0.395 0.397 0.436 0.474 0.476 0.478 0.543 0.608 0.608 0.607 0.633 0.659 0.655 0.651 0.623 0.595 0.595 0.595 0.547 0.498 0.497 0.495 0.522 0.549 0.548 0.546 0.569 0.591 0.593 0.594 0.602 0.609 0.609 0.609 0.607 0.605 0.607 0.608 0.619 0.629 0.629 0.628 0.748 0.867 0.867 0.866 0.902 0.937 0.941 0.944 0.969 0.994 0.991 0.988 0.936 0.883 0.883 0.882 0.855 0.828 0.830 0.831 0.787 0.742 0.744 0.745 0.681 0.616 0.616 0.616 0.533 0.450 0.348];
ProfileRh=[0.246 0.280 0.286 0.301 0.302 0.330 0.397 0.478 0.607 0.651 0.595 0.495 0.546 0.594 0.609 0.608 0.628 0.866 0.944 0.988 0.882 0.831 0.745 0.616];
Is it possible to do it? There is a better way to have a "cleaner" whitut loosing data?

Accepted Answer

Jan
Jan on 22 Jun 2022
Edited: Jan on 22 Jun 2022
You do not mean "strings". Strings are characters enclosed in double quotes. With "open and close groups" you mean the folding code sections in the editor.
It is not clear, what exactly you want to do with the shown block of code, but maybe you want to make it a "code section" to be able to fold it:
%% Profile
ProfileA = [0.400 0.388 0.375 0.363 0.350 0.350 0.350 0.350 0.350 0.375 0.400 0.425 0.450 0.488 0.525 0.563 0.600 0.650 0.700 0.750 0.800 0.850 0.900 0.950 1.000 0.988 0.975 0.963 0.950 0.938 0.925 0.913 0.900 0.913 0.925 0.938 0.950 0.938 0.925 0.913 0.900 0.888 0.875 0.863 0.850 0.813 0.775 0.738 0.700 0.700 0.700 0.700 0.700 0.688 0.675 0.663 0.650 0.663 0.675 0.688 0.700 0.725 0.750 0.775 0.800 0.838 0.875 0.913 0.950 0.963 0.975 0.988 1.000 0.988 0.975 0.963 0.950 0.963 0.975 0.988 1.000 0.975 0.950 0.925 0.900 0.875 0.850 0.825 0.800 0.725 0.650 0.575 0.500 0.475 0.450 0.425];
ProfileAh = [0.400 0.350 0.350 0.450 0.600 0.800 1.000 0.950 0.900 0.950 0.900 0.850 0.700 0.700 0.650 0.700 0.800 0.950 1.000 0.950 1.000 0.900 0.800 0.500];
ProfileC = [0.516 0.511 0.506 0.523 0.540 0.545 0.549 0.537 0.524 0.521 0.518 0.509 0.500 0.500 0.499 0.509 0.519 0.524 0.528 0.550 0.571 0.572 0.573 0.587 0.600 0.600 0.599 0.656 0.713 0.724 0.735 0.811 0.886 0.885 0.883 0.868 0.853 0.849 0.845 0.865 0.884 0.874 0.863 0.901 0.938 0.948 0.958 0.930 0.901 0.909 0.917 0.901 0.884 0.902 0.919 0.899 0.879 0.874 0.869 0.844 0.818 0.811 0.804 0.801 0.798 0.814 0.830 0.805 0.780 0.798 0.815 0.788 0.761 0.763 0.765 0.724 0.682 0.680 0.678 0.678 0.677 0.673 0.669 0.675 0.681 0.687 0.693 0.671 0.649 0.633 0.617 0.598 0.579 0.569 0.558 0.537];
ProfileCh = [0.516 0.540 0.524 0.500 0.519 0.571 0.600 0.713 0.886 0.853 0.884 0.938 0.901 0.884 0.879 0.818 0.798 0.780 0.761 0.682 0.677 0.681 0.649 0.579];
ProfileR = [0.246 0.260 0.274 0.277 0.280 0.282 0.284 0.285 0.286 0.294 0.301 0.301 0.301 0.299 0.296 0.299 0.302 0.314 0.325 0.328 0.330 0.362 0.393 0.395 0.397 0.436 0.474 0.476 0.478 0.543 0.608 0.608 0.607 0.633 0.659 0.655 0.651 0.623 0.595 0.595 0.595 0.547 0.498 0.497 0.495 0.522 0.549 0.548 0.546 0.569 0.591 0.593 0.594 0.602 0.609 0.609 0.609 0.607 0.605 0.607 0.608 0.619 0.629 0.629 0.628 0.748 0.867 0.867 0.866 0.902 0.937 0.941 0.944 0.969 0.994 0.991 0.988 0.936 0.883 0.883 0.882 0.855 0.828 0.830 0.831 0.787 0.742 0.744 0.745 0.681 0.616 0.616 0.616 0.533 0.450 0.348];
ProfileRh = [0.246 0.280 0.286 0.301 0.302 0.330 0.397 0.478 0.607 0.651 0.595 0.495 0.546 0.594 0.609 0.608 0.628 0.866 0.944 0.988 0.882 0.831 0.745 0.616];
%% End Profile
By the way, storing data in large blocks of code is a bad programming practice. Separate code, data and GUI strictly. In your case store the values in a text or binary file. This solves the problem of the poluted code implicitly.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!