aligni to the center character string in array cells

I have a character array. I would like to alligne to the center of cells with a simple funcion or so on.
Thanks

댓글 수: 3

"aligni to the center character string in array cells... I have a character array."
A character array is not the same thing as a cell array of character vectors.
A character array is an array of characters, and has nothing to do with cell arrays.
N/A
N/A 2023년 9월 18일
편집: DGM 2023년 9월 18일
Tanks Steven. I attach the file with screenshot of cells of D, don't seem a center cells alignement
@antonio, you have not attached the file, just a screenshot.
Please attach the file you are working with.

댓글을 달려면 로그인하십시오.

답변 (3개)

If you mean to align the strings in center justification, use strjust -
C1 = {'Euler ';
'Fibonacci';
' Gauss'}
C1 = 3×1 cell array
{'Euler '} {'Fibonacci'} {' Gauss'}
C2 = strjust(C1,'center')
C2 = 3×1 cell array
{' Euler '} {'Fibonacci'} {' Gauss '}
If this is not what you wanted to do, please attach the data and code you are working with and specify what you want do.

댓글 수: 1

Dear Joshi, this is the initial script tu define first two rows of array (winding of mutilayr coil and inductance and mutual inductance calculation)
% Definizione della tabella
Caratt_Filo = [5:5];
% Conversione di Caratt_Filo in un array di stringhe
Caratt_Filo = string(Caratt_Filo);
% Scrittura del Testo
Caratt_Filo(1, 1) = ("Sezione");
Caratt_Filo(1, 2) = ("φ Filo Nudo");
Caratt_Filo(1, 3) = ("Res. D.C.");
Caratt_Filo(1, 4) = ("IMax");
Caratt_Filo(1, 5) = ("IMax f(T)");
Caratt_Filo(2, 1) = ("mm^2");
Caratt_Filo(2, 2) = ("mm");
Caratt_Filo(2, 3) = ("(Ω/m)")
Caratt_Filo(2, 4) = ("A");
Caratt_Filo (2,5) = ("A");
My purpose is to align to the center of cells all the strings, only for aesthetic reason, following allignement on right side of the value of parameters in string format loaded from excel file (but i think this is not possible).
I belive that it appear the only way in matlab to have perfect indented table, also.
I pheraps undersood why i am not able to do that. I think that matlab act as excel, in which the cell width depend on pixels that compose the characters (Font type and dimensions). I can overcame inserting blank at the beginning (only for indent, but i am curious to do that with same embedded funtion. The screen shot tath i sent is just the results of your script inside table in the workspace.
Thanks for your interest
Ciao

댓글을 달려면 로그인하십시오.

DGM
DGM 2023년 9월 18일
편집: DGM 2023년 9월 18일

0 개 추천

So it's either a string array or a cellchar. In either case it has some unknown amount of whitespace on at least one side. It's hard to tell because of the variable-width font. For all we know, it's already padded to the center and this complaint is entirely about the display in the variable browser.
So that's my guess. If this is all about the display in the variable browser, then no, as far as I know there isn't a "center" option (at least not in my older version). However, if the array is already padded with whitespace, it won't display as centered unless you're using a monospace font in the variable browser.
Again, that only solves the display issue of strings/chars that are already padded. It doesn't add the padding to the array.

댓글 수: 1

thanks at this point i think is better, for me, tu put blanck at the beginning of string

댓글을 달려면 로그인하십시오.

N/A
N/A 2023년 9월 18일

0 개 추천

I forget. Perhaps it act as excel in wich if i remember well, the cell width is function of n. of pixel of each font

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품

릴리스

R2022a

질문:

N/A
2023년 9월 18일

댓글:

N/A
2023년 9월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by