Hi
A Question please.
I want to write a function that create a 3-dimension matrix based on two 2-demnesion matrices.
I named this new matrix C.
I write something but when I run it give me "ans" but I want to give me matrix C.
this is my simple code
function Model=Base()
load('test1.mat');
%z1=[90 50 159;148 120 31;142 3 74];
%z2=[13 155 108;141 40 102;109 119 144];
[m,n]=size(z1);
for k=1
c(:,:,k)=z1;
end
for k=2
c(:,:,k)=z2;
end
Model.c=c
end
What is rong in my code please?
Thank you

2 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 1 月 1 日
What is your problem?
mouh nyquist
mouh nyquist 2015 年 1 月 1 日
see help cat

サインインしてコメントする。

 採用された回答

Shoaibur Rahman
Shoaibur Rahman 2015 年 1 月 1 日

1 投票

If you use your current code, then call your function create1() (from command window, or in another m-file):
c = create1();
This will show c in your workspace as a struct.
But if want to see c as double instead of struct, then modify the last line of your code. Replace Model.c=c by Model = c
Then type c = create1() in your command window, which will show c in the workspace.

3 件のコメント

fatema saba
fatema saba 2015 年 1 月 1 日
Thank you but is it any way that I can get c variable in my workspace only with run creat1.m without typing c=creat1() from command window.
Shoaibur Rahman
Shoaibur Rahman 2015 年 1 月 1 日
You you can. But in that case you cannot use function here. Instead, use just a part of your code, and save and run it.
z1=[90 50 159;148 120 31;142 3 74];
z2=[13 155 108;141 40 102;109 119 144];
c=cat(3,z1,z2)
fatema saba
fatema saba 2015 年 1 月 1 日
Thank you and all the other friends

サインインしてコメントする。

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 1 月 1 日

1 投票

c=cat(3,z1,z2)

5 件のコメント

fatema saba
fatema saba 2015 年 1 月 1 日
thank you
I change my code with your tip.
function Model=create1()
%load('test1.mat');
z1=[90 50 159;148 120 31;142 3 74];
z2=[13 155 108;141 40 102;109 119 144];
c=cat(3,z1,z2)
Model.c=c
but in my workspace I get "ans" variable. but I want to get "C" variable in my workspace directly. I need it.
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 1 月 1 日
It's not C but c. Just type
c
you will see the result
fatema saba
fatema saba 2015 年 1 月 1 日
no I type it but
>> c ??? Undefined function or variable 'c'.
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 1 月 1 日
But your function return just the variable model , in this case just type
Model
fatema saba
fatema saba 2015 年 1 月 1 日
no I have done but..
>> Model
??? Undefined function or variable 'Model'.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Numeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by