How do I have my variable output be uniform?
Afficher commentaires plus anciens
I would like the following output (as shown in the attached pic), to be either just horizontal (i.e., single column), or vertical (i.e., two columns) for each series of vertex coordinates. Right now, each series larger than 5 pairs of coordinates is listed as a double (or two column output), as shown in the pic with red arrows. Conversely, each series smaller than 6 pairs of coordinates is listed in a single, horizontal cell. Could someone let me know how to change the code (and/or Matlab preferences) such that the output would be uniform? Thanks in advance for any help you could offer.

Relevent Section of Code:
% for each internal cell, obtain vertex coordinates.
faVrInf=cell(size(bndPx,1),1);
for i=1:size(vrInf,1)
for j=3:length(vrInf{i})
faVrInf{vrInf{i}(j)}(end+1,:)=[vrInf{i}(1),vrInf{i}(2)];
end
end
% find position of vertex coordinates in boundary pixel lists.
faVrPsInf=cell(size(faVrInf,1),1);
for i=1:size(faVrInf,1)
if any(intCell==i)==1
for j=1:size(faVrInf{i},1)
faVrPsInf{i}(j)=find(ismember(bndPxSrt{i},faVrInf{i}(j,:),...
'rows'),1);
end
faVrPsInf{i}=sort(faVrPsInf{i});
end
end
5 commentaires
Rik
le 24 Avr 2022
I can't tell what your edit changed. Can you comment with what you changed and/or why neither answer works for you?
Rik
le 24 Avr 2022
Thanks to everyone for all your input. I ultimately would like to be able to compare values (x, y coordinates) stored in two different variables, and then to store only the values that are within a certain tolerance of discrepancy in a third variable. Regarding the edits I made--I just changed the section of code that I had included in my original submission--the previous code that I posted was not the correct one (i.e., the variable of interest is: faVrInf). Below was the original section of code (I believe) I had up:
% find position of vertex coordinates in boundary pixel lists.
faVrPsInf=cell(size(faVrInf,1),1);
for i=1:size(faVrInf,1)
if any(intCell==i)==1
for j=1:size(faVrInf{i},1)
faVrPsInf{i}(j)=find(ismember(bndPxSrt{i},faVrInf{i}(j,:),...
'rows'),1);
end
faVrPsInf{i}=sort(faVrPsInf{i});
end
end
% Count number of edges for each internal cell and add up
edTtNum=0;
for i=1:size(faVrInf,1)
if any(intCell==i)==1
edTtNum=edTtNum+size(faVrInf{i},1);
end
end
Rik
le 24 Avr 2022
Then your question is how to filter the values in each cell depending on that tollerance? The display is only relevant if you look at the values yourself, which you should probably not use to apply any filtering, as it is easy to make a mistake.
Steven D
le 24 Avr 2022
Rik
le 24 Avr 2022
You can also write all the data to excel if you so choose, but even then, it doesn't matter how the data is displayed in Matlab, only how it stores it in your excel file.
Réponses (2)
Rik
le 23 Avr 2022
0 votes
Arrays in Matlab must be rectangular. The image you show does not show how the data is stored, it is merely a display. For longer arrays, the data is summarized with just the size and the type.
If you want to make each cell contain the same size array, you will have to either extend the smaller arrays, or remove elements from the larger arrays. Which of these you want is not clear to me from your question. Right now, all your data is in two-column matrices.
Walter Roberson
le 23 Avr 2022
Modifié(e) : Walter Roberson
le 23 Avr 2022
0 votes
You are using the variable browser. The variable browser does not provide any way to customize the output for Mathworks-provided datatypes -- other than choosing the default format specification for the times that it displays contents at all.
If you were defining your own object class, then you would be able to customize the display, with sufficiently new versions of MATLAB. See https://www.mathworks.com/help/matlab/group_analysisopt.html
To do what you want, you would have to design your own display routines instead of using the variable browser.
You could cellfun(@mat2str) your cell and display the results, but if I recall correctly that display will also eventually truncate and show you "..." instead of the rest of the output.
Historically the number of elements displayed in the command window depended on the width of the command window -- but it had to be somewhere around 2400 pixels wide before the first increase in number of elements occurred (I do not recall the exact boundary; wider than most people's displays though.) I have not checked to see if that is still the case. In the time since I last looked at that code, Mathworks increased the default number of values displayed in the command window. And command window is not the same as the variable browser anyhow.
Catégories
En savoir plus sur Data Import from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!