You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Fill matrix with random letters and numbers
7 views (last 30 days)
Show older comments
Accepted Answer
Fangjun Jiang
on 10 Aug 2011
A9=['A':'Z' '0':'9';];
Data=zeros(length(A9),20);
for k=1:size(Data,2)
Data(:,k)=randperm(length(A9));
end
Data=A9(Data)
17 Comments
Fangjun Jiang
on 10 Aug 2011
Reading the MATLAB document is a good start. Watch some video from Doug Hull form the Mathworks website help also. You can run the above code step by step, watch the value of the variable and understand the underline operation.
Fangjun Jiang
on 11 Aug 2011
To help understanding, maybe try this simple one first:
a=['A':'D']
b=randperm(4)
c=a(b)
Paulo Silva
on 11 Aug 2011
Another alternative way (little bit slower) but without the for loop:
A=['A':'Z' '0':'9'];
Data=cell2mat(arrayfun(@(x)randperm(length(A)),1:20,'uni',false)')';
Data=A(Data);
Paulo Silva
on 11 Aug 2011
Using this xlswrite('testexcel',Data) you don't need delimiter, each array value goes into its own cell
Frank
on 12 Aug 2011
Paulo (or whoever else reads this)--
xlswrite('testexcel',Data) did indeed do what you said it would, but it created an excel workbook with two sheets--one with the numbers, the other with the text. How do you merge the two?
Thanks in advance.
Paulo Silva
on 12 Aug 2011
Frank are you sure that it created two sheets?
What I see is one sheet with the letters and numbers, the letters appear on the left of each cell and the numbers on the right but this is the way excel seems to work, you can select all in excel and choose the text format for all cells, that way all appear on the left of the cells.
Frank
on 12 Aug 2011
Paulo, what I see (pardon if I'm too explicit) is a file in the Current Folder that says testexcel.xls
When I click on that, the Import Wizard opens up; at the top there are two tabs--one labeled "data" on the left and one labeled "textdata" on the right. I click through the Import Wizard , select "Finish" and then the Import Wizard closes.
I know it's something simple, but what am I missing? Thanks for your patience.
Fangjun Jiang
on 12 Aug 2011
Okay, you can one-right-click on the Excel file and choose "Open Outside MATLAB", it will open the file using Excel. You'll see the Excel file is right except numbers are at the left at each cell and letters are on the right of each cell. That is just the smart formatting of Excel.
What you saw was [Num,Text, Raw]=xlsread('ttestexcel.xls'). It tries automatically to separate numeric and text data. The original data is always in the variable 'Raw'.
Paulo Silva
on 12 Aug 2011
Frank you didn't specify the use of the import wizard you just told me about the excel file, I also don't know why you are using the excel part, why don't you just save the data to a mat file?
Frank
on 12 Aug 2011
Fangjun, thank you for your help.
I wanted to save the data to an excel file because it is easier for me to handle and to enter client data into.
Paulo, as I gain experience with MATLAB I'll use it more and more. I am less than a beginner with matlab--if there is a pre-neophyte category, then that describes me. Sorry for any confusion I caused.
Paulo Silva
on 12 Aug 2011
No problem Frank, just in case you don't need the excel file you can just save the variable Data to a mat file
save('MyData','Data')
and load it when you need to use it
load('MyData')
the variable appears again on your workspace with the same name and contents.
More Answers (0)
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)